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
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.
EDIT:
According to the new information this should work in the .htaccess
file:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{QUERY_STRING} ^.+$
RewriteRule ^(.*)$ /$1? [R=301,L]
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]