简体   繁体   English

.htaccess 重写所有,除了一页

[英].htaccess rewrite all, except one page

I am trying to solve a problem with my .htaccess file.我正在尝试解决我的 .htaccess 文件的问题。

I would like to use 301 redirect from my "old" doman to the "new" one, except some certain pages.我想使用 301 重定向从我的“旧”域到“新”域,但某些页面除外。 Like "PageA" and "PageB".像“PageA”和“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. “PageA”和“PageB”也必须重定向到“新”域,但重定向到某个地址。 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 ?我应该向 .htaccess 添加什么代码,以添加某些地址的例外情况?

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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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