将包含特定字符串的 url 重定向到问号前的 url [英] Redirect url containg a specific string to url before question mark
问题描述
我有一些具有以下结构的网址:
https://www.example.com/name-of-a-page?specific_string-anything
我想将此类网址重定向到:
https://www.example.com/name-of-a-page
换句话说,我想将包含特定字符串的 url 重定向到位于问号之前的 url 部分.
我预先感谢您在这方面提供的任何帮助.
帕特里克
I have some urls with the following structure :
https://www.example.com/name-of-a-page?specific_string-anything
I would like to redirect such urls to :
https://www.example.com/name-of-a-page
In other words, I would like to redirect urls containing a specific string, to the part of url located before the question mark.
I thank you in advance for any help in this matter.
Patrick
推荐答案
一个简单的正则表达式来匹配该部分是 [^\?]+(?=\?)
.
A simple regex to get matching that part would be [^\?]+(?=\?)
.
我无法为您提供任何其他信息,因为我不知道您喜欢使用哪种语言.
I can't give you any other information because I don't know what language you like to use.
根据新信息,这应该在 .htaccess
文件中工作:
According to the new information this should work in the .htaccess
file:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{QUERY_STRING} ^.+$
RewriteRule ^(.*)$ /$1? [R=301,L]
编辑 2:
根据最新信息;)代码应该是这样的:
EDIT 2:
According to the latest information ;) the code should be this:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{QUERY_STRING} ^specific_string.*$
RewriteRule ^(.*)$ /$1? [R=301,L]
这篇关于将包含特定字符串的 url 重定向到问号前的 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!