mod_rewrite IS very straightforward and what you got wrong is that your code is ONLY designed to strip the www from the URI. Do you have both the non-www and the www version allowed by your host (because your code should work as you expect)?
RewriteCond %{HTTP_HOST} ^www\\.(([a-z0-9_]+\\.)?zvis\\.com)$ [NC]
# RewriteRule ^(.*)$ http://%1/$1 [R=301,L,QSA]
# the following will do the job just as well and is easier to understand
# QSA is automatic UNLESS you're creating a new query string
RewriteRule .? http://%1/%{REQUEST_URI} [R=301,L]
You should be able to tell about the host if you can see the DNS records - otherwise, ask them to enable the non-www version of your domain.
[quote=dklynn;4489339Do you have both the non-www and the www version allowed by your host
…
You should be able to tell about the host if you can see the DNS records - otherwise, ask them to enable the non-www version of your domain.
[/quote]
I’m maintaining dns records myself. So, I guess I am missing something but what? in dns I can see records for @ and www as A type… Anything else I should have?
In my DNS record, I have my domain name, 14400, IN, A and my IP address. Following that, I have www, 14400, IN, CNAME, my domain name. Those are the relevant settings in my WHM DNS panel. If you’re using your own VirtualHost file, include the non-www’d domain name in the declaration.
Well, I sortta found a reason, but I don’t understand why.
In the child directory which refuses to redirest www to non www there is another .htaccess.
In that htaccess I have other local redirect rules. But they’re irrelevant since,
even if I put just these 2 lines in the child dir .htaccess
RewriteEngine on
RewriteEngine Off
www doesn’t get redirected anymore… I thought top level was processed first?
The top level IS processed first so you are correct. By the time the subdirectory’s .htaccess is parsed, the redirection should already have been made.