带有Sting查询问题的正则表达式

时间:2015-09-23 20:00:00

标签: regex .htaccess mod-rewrite

我已尝试过以下

RewriteEngine On
RewriteCond %{QUERY_STRING} ^slides=(.*)$
RewriteRule ^/([a-zA-Z\-0-9_]+)/.*$ /$1/ [R=301,L]

对于URLS来说 http://example.com/whatever-in-here/?slides=asdf被重定向到http://example.com/whatever-in-here/?

然而它不起作用

2 个答案:

答案 0 :(得分:0)

你应该使用

RewriteRule ^/([a-zA-Z\-0-9_\.\/]+\/\?).*$ /$1/

将删除?后匹配中的所有内容。 demo

答案 1 :(得分:0)

要剥离查询字符串,您可以在目标中添加?

RewriteEngine On

RewriteCond %{QUERY_STRING} ^slides=(.*)$
RewriteRule ^ %{REQUEST_URI}? [NE,R=301,L]

另请注意,您不需要在RewriteRule中对URI进行分组和捕获,因为您可以使用%{REQUEST_URI}

相关问题