简体   繁体   中英

.htaccess rewrite all, except one page

I am trying to solve a problem with my .htaccess file.

I would like to use 301 redirect from my "old" doman to the "new" one, except some certain pages. Like "PageA" and "PageB".

The code thats working and iam using for redirect all is this:

RewriteCond %{HTTP_HOST} ^old.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.old.com [NC]
RewriteRule ^(.*)$ http://www.new.com/$1 [L,R=301,NC]

"PageA", and "PageB" has to be redirected to the "new" domain too, but to a certain address. Like:

old.com/pageA  ---> new.com/something/pageA
old.com/pageB  ---> new.com/something2/pageB

What code should i add to .htaccess, to add some exceptions with certain addresses ?

Try below rule,

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/(pageA|pageB)$
RewriteRule ^ http://www.new.com/test/%1 [L,R=301,NC]

RewriteCond %{HTTP_HOST} ^old.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.old\.com [NC]
RewriteRule ^ http://www.new.com/$1 [L,R=301,NC]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM