htaccess 301 redirect entire site but with exceptions

ⅰ亾dé卋堺 提交于 2019-12-19 18:28:13

问题


I am trying to create an htaccess file to redirect my entire site except with some exceptions, but I can't get it working. I need to redirect the entire thing, provide a specific redirect, and exclude two pages. Below is my non-working sample. Thanks!

RewriteCond %{REQUEST_URI} !^/events/index.html
RewriteCond %{REQUEST_URI} !^/calendar/index.html
Redirect 301 /info/faq.html http://mynewsite.com/my-page
Redirect 301 / http://mynewsite.com

回答1:


You're attempting to mix mod_rewrite with mod_alias, but the RewriteCond statements cannot condition the Redirect statements, as they don't come from the same module.

I believe you want something more like this, if I've correctly understood what you were trying to accomplish:

RewriteEngine On

RewriteCond %{REQUEST_URI} !=/events/index.html
RewriteCond %{REQUEST_URI} !=/calendar/index.html
RewriteCond %{REQUEST_URI} !=/info/faq.html
RewriteRule ^.*$ http://mynewsite.com/$0 [R=301,L]

Redirect 301 /info/faq.html http://mynewsite.com/my-page



回答2:


I had a similar issue. Trying to redirect an entire domain with the exception of its robots.txt file. Tim's answer didn't work for me, but this did

RewriteEngine On
RewriteRule robots.txt - [L]
RewriteRule ^.*$ http://www.newsite.com/$0 [R=301,L]


来源:https://stackoverflow.com/questions/3372344/htaccess-301-redirect-entire-site-but-with-exceptions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!