我的.htaccess
文件中有两种不同的规则。第一组匹配精确文件,然后我有一个通用的catch-all用于其他所有内容。我已经读过你可以使用[L]
来重写规则,但有Redirect 301
的等价物吗?例如,我的.htaccess
文件如下所示:
Redirect 301 /exact_page.html http: //www.newsite.com/new_page1.html
Redirect 301 /some_other_page.html http ://www.newsite.com/new_page2.html
RewriteEngine on
RewriteRule ^(.*)$ http://www.newsite.com/$1 [R=301,L]
我希望页面exact_page.html
和some_other_page.html
完全按照所示方式重定向,其他所有内容都会从域中获取映射到新域,其余网址保持不变。相反,在我看来,前两个Redirect 301
被忽略,或者更确切地说,被最终规则所取代。有没有办法告诉apache在找到第一场比赛后停止?
答案 0 :(得分:1)
我认为这样的事情应该有效:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/(exact_page\.html|some_other_page\.html)$
RewriteRule ^(.*)$ http://www.newsite.com/$1 [R=301,L]
RewriteRule ^exact_page\.html$ http://www.newsite.com/new_page1.html [R=301,L]
RewriteRule ^some_other_page\.html$ http://www.newsite.com/new_page2.html [R=301,L]