I hav开发者_StackOverflow社区e a wordpress blog on /blog
which is configured to run without www. so the blog url is: http://domain.com/blog/
I need to redirect all traffic from:
www.domain.com
domain.com
www.domain.com/*
domain.com/*
www.domain.com/blog/
www.domain.com/blog/*
So that that the root goes to the blog and any www. that have been added or are incorrectly configure will be stripped.
I do not seem to be able to configure the .htaccess file in the root /
and in /blog/
to work.
These rules should do the job (although some REAL testing is required as I was just simulating all URls):
RewriteEngine On
RewriteBase /
# add trailing slash in /blog if absent
RewriteRule ^blog$ http://domain.com/blog/ [NC,QSA,R=301,L]
# redirect to /blog/ on domain.com
RewriteCond %{HTTP_HOST} =domain.com
RewriteRule ^(?!blog/?)(.*)$ http://domain.com/blog/$1 [NC,QSA,R=301,L]
# redirect to /blog/ on www.domain.com
RewriteCond %{HTTP_HOST} =www.domain.com
RewriteRule ^(blog/)?(.*)$ http://domain.com/blog/$2 [NC,QSA,R=301,L]
If some URL does NOT redirect then let me know (FULL URL) so I can look into it.
精彩评论