开发者

htaccess redirection to /blog removing www from all locations

开发者 https://www.devze.com 2023-03-18 06:04 出处:网络
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 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消