2

I have a domain example.com in which I'm doing this to redirect all my traffic from www version to non-www:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

Everything fine until now. I can do www.example.com to example.com, but I also have another domain which I am hosting on the same account as a addon domain. Like there is a folder like example.org in my base www directory of example.com.

Now when I'm doing www.example.org, I get http://example.com/example.org with an additional 404.

Hope you get my point. Thanks in advance.

1 Answer 1

2

This occurs because the .htaccess will be inherited in all child directories. This is a common issue when using add-on domains because each domain shares the same path environment.

This can be resolved by any of the following:

  • Use more secure hosting with jailed accounts
  • Use a .htaccess in each add-on domain child directory
  • Use %{HTTP_HOST} ^www.example.com [NC] rather than %{HTTP_HOST} ^www.(.+)$ [NC]
2
  • I opt to go for third one. :D Jun 18, 2015 at 16:05
  • 1
    Just a note on the "Use a .htaccess in each add-on domain child directory" - you would also need to (at least) enable the rewrite engine (ie. RewriteEngine On) in the child directory's .htaccess file in order to prevent the parent mod_rewrite directives being "inherited".
    – MrWhite
    Jun 18, 2015 at 22:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.