问题
Can someone help? For some reason the 301 redirects are not working.... The rewrite conditons format my urls by removing the extensions, so not sure if I need to remove the extensions from the 301 statements or not.
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.beingchildren\.org$ [NC]
RewriteRule ^(.*) http://www.beingchildren.org/$1 [L,R=301]
RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.htm[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.htm -f
RewriteRule ^(.+?)/?$ /$1.htm [L]
errordocument 404 /404.php
Redirect 301 /Blog/2012-12-25-Christmas-Presents.htm http://www.beingchildren.org/Children-Charity-Blog
Redirect 301 /Blog/2013-03-29-Mixed-Slum-Photos.htm http://www.beingchildren.org/Children-Charity-Blog
Redirect 301 /Blog/2013-05-14-Monthly-Slum-Visits-1.htm http://www.beingchildren.org/Children-Charity-Blog
Redirect 301 /Blog/2013-06-12-Panjim-Monsoon.htm http://www.beingchildren.org/Children-Charity-Blog
Redirect 301 /Blog/2013-06-15-Margao-Charity-Donations-1.htm http://www.beingchildren.org/Children-Charity-Blog
Redirect 301 /Blog/2013-09-08-Margao-Ganesh-Celebrations.htm http://www.beingchildren.org/Children-Charity-Blog
Redirect 301 /Blog/2013-09-08-Margao-Ganesh-Holidays.htm http://www.beingchildren.org/Children-Charity-Blog
Redirect 301 /Charity.htm http://www.beingchildren.org
Redirect 301 /Children-Charity-Pictures.htm http://www.beingchildren.org/Children-Charity-Blog
回答1:
It is because of 2 issues:
- 301 rules are at the bottom after
.htm
is removed - mixing of
mod_alias
andmod_rewrite
rules
Try this code instead:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.beingchildren\.org$ [NC]
RewriteRule ^(.*) http://www.beingchildren.org/$1 [L,R=301]
RewriteRule ^Blog/2012-12-25-Christmas-Presents\.htm$ http://www.beingchildren.org/Children-Charity-Blog [L,R=301,NC]
RewriteRule ^Blog/2013-03-29-Mixed-Slum-Photos\.htm$ http://www.beingchildren.org/Children-Charity-Blog [L,R=301,NC]
RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.htm[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.htm -f
RewriteRule ^(.+?)/?$ /$1.htm [L]
PS: I have converted only top 2 of your 301 rules. Once those are working you can similarly convert rest.
来源:https://stackoverflow.com/questions/21542017/301-redirects-not-working-anyone-know-why