I use such redirect code in .htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*)$ %{HTTP_HOST}$1 [C]
RewriteRule ^www\.(.*)$ http://$1 [L,R=301]
When I type: www.domain.com/file.php it works ok forwarding to domain.com/file.php
When I type: www.domain.com/folder/folder2 I’m redirected to: domain.comfolder/folder2 (with no slash)
How can I fix this?
Not sure why that’s happening, but those rules don’t work at all when I put them in my htaccess file in a vanilla apache 2.2 install. Since it looks like all you’re doing is redirecting a http://www.domain.com request to a domain.com request, you could just do this:
Instead of chaining rules together and rewriting the host into the URI-path.