重定向剥离匹配的字符串-htaccess

发布于 2025-02-06 02:08:48 字数 525 浏览 3 评论 0原文

使用.htaccess,我想重定向所有包含的页面 - Nocolor-在其URL末尾。我希望没有比赛将它们重定向到同一URL。

例子: https://www.test.com/products/test--nocolor-https://www.test.com/products/test

我尝试过的是

RewriteCond %{REQUEST_URI} (--nocolor-)

工作,但是我在重写时无法获得正确的URL。 我已经尝试过

RewriteRule ^products/([^/]*)(?=--nocolor-) /$1 [R=301,L]
RewriteRule ^(.+)(?=--nocolor-) /$1 [R=301,L]
RewriteRule ^.*(?=--nocolor-) /$1 [R=301,L]

,但是我总是以$ 1为空。 我做错了什么?

Using .htaccess, I want to redirect all the pages which contains --nocolor- at the end of their url. I want redirect them to the same url without the match.

Example:
https://www.test.com/products/test--nocolor-
to
https://www.test.com/products/test

What I've tried is

RewriteCond %{REQUEST_URI} (--nocolor-)

and that is working but I cannot get the right url while rewriting.
I've tried

RewriteRule ^products/([^/]*)(?=--nocolor-) /$1 [R=301,L]
RewriteRule ^(.+)(?=--nocolor-) /$1 [R=301,L]
RewriteRule ^.*(?=--nocolor-) /$1 [R=301,L]

but I always end up with $1 empty.
What do I do wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夕色琉璃 2025-02-13 02:08:48

使用您显示的样本,请尝试遵循.htaccess规则。确保将这些规则放在您的.htaccess规则之上。

另外,请确保在测试URL之前清除浏览器缓存。

RewriteEngine ON
RewriteCond %{THE_REQUEST} \s/(.*)--nocolor-\s [NC]
RewriteRule ^ /%1 [R=301,L]

With your shown samples, attempts please try following .htaccess rules. Make sure to place these rules at top of your .htaccess rules.

Also make sure to clear your browser cache before testing your URLs.

RewriteEngine ON
RewriteCond %{THE_REQUEST} \s/(.*)--nocolor-\s [NC]
RewriteRule ^ /%1 [R=301,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文