禁用特定页面的301重定向。

huangapple go评论67阅读模式
英文:

disable 301 redirect for specific for specific pages

问题

我正在将我的域名从 **www.old.com** 更改为 **www.new.com**,为此我正在使用 `.htaccess` 文件进行 **301** 重定向,目前一切正常,但问题是我不想重定向特定页面。

例如 **www.old.com/my-account** 或 **www.old.com/checkout**。有人能帮我解决吗?

RewriteEngine on
RewriteRule (.*) https://www.new.com/$1 [R=301,L]


<details>
<summary>英文:</summary>

I&#39;m changing my domain **www.old.com** to **www.new.com**, for that m using **301** redirects via `.htaccess`, and it&#39;s working fine, but the issue is I don&#39;t want to redirect my specific pages. 

for example **www.old.com/my-account** or **www.old.com/checkout**. Can someone help me out?

RewriteEngine on
RewriteRule (.*) https://www.new.com/$1 [R=301,L]


</details>


# 答案1
**得分**: 3

两个明显的选项:

你可以添加条件到你现有的规则中:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/my-account/?$
RewriteCond %{REQUEST_URI} !^/checkout/?$
RewriteRule ^ https://new.example.com%{REQUEST_URI} [R=301,L]


或者你可以添加例外情况,这些例外情况会在一般重定向之前应用:

RewriteEngine on
RewriteRule ^/?my-account/?$ - [L]
RewriteRule ^/?checkout/?$ - [L]
RewriteRule ^ https://new.example.com%{REQUEST_URI} [R=301,L]


这两种替代方法可以在HTTP服务器的主机配置中实现,或者如果你无法访问主机配置,可以在分布式配置文件(".htaccess")中实现。

<details>
<summary>英文:</summary>

Two obvious options: 

You could add conditions to your existing rule: 

    RewriteEngine on 
    RewriteCond %{REQUEST_URI} !^/my-account/?$
    RewriteCond %{REQUEST_URI} !^/checkout/?$
    RewriteRule ^ https://new.example.com%{REQUEST_URI} [R=301,L]

Or you could add exceptions that get applied _before_ the general redirection: 

    RewriteEngine on 
    RewriteRule ^/?my-account/?$ - [L]
    RewriteRule ^/?checkout/?$ - [L]
    RewriteRule ^ https://new.example.com%{REQUEST_URI} [R=301,L]

Both alternatives can be implemented in the http server&#39;s host configuration, or, if you have no access to that, in an distributed configuration file (&quot;.htaccess&quot;). 


</details>



huangapple
  • 本文由 发表于 2023年2月24日 14:11:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/75553151.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定