简体   繁体   English

如何 301 重定向特定页面以删除部分 URL?

[英]How do I 301 redirect specific pages to remove part of the URL?

Every URL that begins with:每个以以下开头的 URL:

https://example.com/usa/example-1/

I want to redirect to a URL with example-1 changed to example-2 :我想重定向到example-1更改为example-2的 URL:

https://example.com/usa/example-2/

for example, this URL:例如,这个网址:

https://example.com/usa/example-1/state/city/

to be redirected to:重定向到:

https://example.com/usa/example-2/state/city/

etc.等等。

Can you help?你能帮我吗? I always have a hard time using .htaccess so I prefer to ask before testing.我总是很难使用.htaccess所以我更喜欢在测试前询问。

.htaccess文件的顶部尝试类似以下内容:

RewriteRule ^(usa)/example-1/(.*) /$1/example-2/$2 [R=301,L]

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

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