Question

I have a cPanel hosting account with my primary domain pointing to public_html. But, to make directory structure better, I add the following code to public_html/.htaccess

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/www\.MyDomain\.com [NC]
RewriteRule ^(.*)$ /MyDomain.www/$1 [NC,L]

It simply redirect all request from /public_html to /public_html/MyDomain.www for my primary domain.

But, the problem is when I visit http://www.MyDomain.com/ it dispays page at public_html/MyDomain.www/index.php but with 403 HTTP code instead of 200 which is expected. Note, visiting http://www.MyDomain.com/index.php returns page correctly with 200 HTTP code.

So, How can I fix the 403 error code?

Was it helpful?

Solution

I tried replacing the existing rewrite rule in .htaccess with this and surprisingly it worked.

RewriteCond %{HTTP_HOST} ^domain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteCond %{REQUEST_URI} !domain.www/
RewriteRule (.*) /domain.www/$1 [L] 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top