重定向剥离匹配的字符串-htaccess
使用.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-
tohttps://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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用您显示的样本,请尝试遵循.htaccess规则。确保将这些规则放在您的.htaccess规则之上。
另外,请确保在测试URL之前清除浏览器缓存。
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.