salted
asked on
mod_rewrite rules to drop www prefix
I'm trying to write some mod_rewrite rules to drop a www prefix from http://www.example.com and redirect to http://example.com
Using Apache 1.3 and mod_rewrite I have the following rule set for the root of the site.
rewritecond %{http_host} ^www\.example\.com [nc]
rewriterule ^(.*)$ http://example.com/$1 [r=301,L]
This works fine for the root of the site, however I have another set of rewrite directives in the /blog/ subfolder to handle redirects for a wordpress blog so I need to declare rewrite rules in there as well.
For the /blog/ subfolder the .htaccess is
rewritecond %{http_host} ^www\.example.com [nc]
rewriterule ^(.*)$ http://example.com/blog/$1 [r=301,L]
This rule works fine if someone vists http://www.example.com/blog/ and redirects to http://example.com/blog/
However, if someone visits and leaves out the trailing slash, http://www.example.com/blog then the redirect goes funny and appends the local directory structure of the site so the URL looks like:
http://example.com/blog//home/users/xyz/domains/example.com/public_html/blog
Any ideas where I'm going wrong?
Using Apache 1.3 and mod_rewrite I have the following rule set for the root of the site.
rewritecond %{http_host} ^www\.example\.com [nc]
rewriterule ^(.*)$ http://example.com/$1 [r=301,L]
This works fine for the root of the site, however I have another set of rewrite directives in the /blog/ subfolder to handle redirects for a wordpress blog so I need to declare rewrite rules in there as well.
For the /blog/ subfolder the .htaccess is
rewritecond %{http_host} ^www\.example.com [nc]
rewriterule ^(.*)$ http://example.com/blog/$1 [r=301,L]
This rule works fine if someone vists http://www.example.com/blog/ and redirects to http://example.com/blog/
However, if someone visits and leaves out the trailing slash, http://www.example.com/blog then the redirect goes funny and appends the local directory structure of the site so the URL looks like:
http://example.com/blog//home/users/xyz/domains/example.com/public_html/blog
Any ideas where I'm going wrong?
ASKER
I'm on a shared hosting server so I can't access the httpd.conf to set that. Unless of course it is possible to set that in .htaccess?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi periwinkle -
WE also not receive any response from the salted so we can't assume what is going their so please author comment necessory for everyone to final disposition and may be his problem solved.
So we are waiting for author comment.
WE also not receive any response from the salted so we can't assume what is going their so please author comment necessory for everyone to final disposition and may be his problem solved.
So we are waiting for author comment.
ServerName example.com
UseCanonicalName On
(and get rid of the rewrite rules)