.htaccess 301重定向不起作用-有人知道为什么吗?

.htaccess 301重定向不起作用-有人知道为什么吗?,.htaccess,redirect,http-status-code-301,.htaccess,Redirect,Http Status Code 301,有人能帮忙吗?由于某些原因,301重定向无法工作。。。。重写条件通过删除扩展来格式化URL,因此不确定是否需要从301语句中删除扩展 Options +FollowSymlinks RewriteEngine on RewriteCond %{HTTP_HOST} !^www\.beingchildren\.org$ [NC] RewriteRule ^(.*) http://www.beingchildren.org/$1 [L,R=301] RewriteCond %{THE_REQUE

有人能帮忙吗?由于某些原因,301重定向无法工作。。。。重写条件通过删除扩展来格式化URL,因此不确定是否需要从301语句中删除扩展

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

这是因为两个问题:

  • 删除
    .htm
    后,301规则位于底部
  • 混合使用
    mod_别名
    mod_重写
    规则
请尝试以下代码:

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:我只转换了301规则中的前2条。一旦这些都起作用了,你就可以同样地转换rest。

因此,如果我按照重写规则执行rest-使用方括号中的301,我将不再需要单独的重定向301条件??是的,正确,你将不需要那些
重定向301
行。