Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess 301 redirect entire site but with exceptions

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
like image 313
Vincent Avatar asked Jul 30 '10 14:07

Vincent


2 Answers

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
like image 193
Tim Stone Avatar answered Sep 22 '22 19:09

Tim Stone


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]
like image 35
tomhoeck Avatar answered Sep 21 '22 19:09

tomhoeck