I have setup an .htccess
file to redirect www to non-www and also remove trailing slashes. I also have to make sure that business.domain.com
also redirects (301) to domain.com
. The other rules work except redirecting business.domain.com
.
<IfModule mod_rewrite.c>
RewriteEngine On
# redirect to non-www
RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
# redirect business subdomain to no subdomain
RewriteCond %{HTTP_HOST} ^business.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
# redirect non-trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} (.*)$
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Any ideas why the 2nd cond/rule isn’t taking effect?
You might be running into a trailing slash. How about either:
Or just
For your information, you’re making a mistake when you redirect to a top level domain (unless you have huge bandwidth): setting cookies for a prefixless domain sets them across all subdomains… and sessions always set cookies.
Anyway, here’s a rule that works flawlessly for me:
And I have the opposite as well: