mod_rewrite FAQ wrote:To remove www. from all sub domains and domains, put the following in a .htaccess in your document root
- Code: Select all
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
no-www.org wrote:
- Code: Select all
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
The setup:
root -> domains -> domain.tld -> public_html
public_html contains the .htaccess file and a folder named sub for sub.domain.tld
The result:
OK http://domain.tld/ stays http://domain.tld/
OK http://www.domain.tld/ goes to http://domain.tld/
OK http://sub.domain.tld/ stays http://sub.domain.tld/
NOT OK http://www.sub.domain.tld/ goes to http://sub.domain.tld/sub/
Expected behaviour http://www.sub.domain.tld/ goes http://sub.domain.tld/
I use DirectAdmin (well, my host uses it), and at the DirectAdmin forum I was advised to use separate .htaccess files for each subdomain. That shouldn't be necessary with this code, right?
I said I understand the workaround, but that the code does not behave as expected, and got this reply.
Subdomains have their own VirtualHost entries, so even if they share the domain.tld part and are located in a subdirectory, they are their "own entities" with their own webroot. That's why I wouldn't call domain.tld and sub.domain.tld having their own .htaccess rules exactly a workaround.
Does anyone here have any idea why the code is not behaving as expected?
Thank you