从与htaccess的基础URL删除变量 [英] Remove variable from base URL with htaccess
问题描述
我一直在试图重写URL,例如
I've been trying to rewrite a URL such as
www.somesite.com/?x=372
www.somesite.com/?x=372
到网址
www.somesite.com /
www.somesite.com/
我目前的code似乎没有正常工作
My current code does not seem to work
RewriteEngine叙述在
RewriteEngine On
的RewriteCond%{QUERY_STRING} x =(。*)
RewriteCond %{QUERY_STRING} x=(.*)
重写规则 http://www.somesite.com/ [R = 301,L]
RewriteRule http://www.somesite.com/ [R=301,L]
我已经看了试图与htaccess的,仍然没有成功做了无数的方法。
I've looked up countless ways of trying to do it with htaccess and still no success.
推荐答案
如果您只是想重定向客户端删除的查询字符串(一切后,在 ?
的网址),那么你可以试试这个:
If you simply want to redirect a client to remove the query string (everything after the ?
in the URL), then you can try this:
RewriteEngine On
RewriteCond %{QUERY_STRING} x=(.*)
RewriteRule ^ http://www.somesite.com/? [R=301,L]
您已经得到大部分是正确的,它似乎,但你的规则需要有一个比赛,你的目标( http://www.somesite.com/
)需要一个 ?
在最后,这样的重写将不会被追加之前的任何查询字符串。
You've got most of it right, it seems, but your rule needs to have a match, and your target (the http://www.somesite.com/
) needs a ?
at the end so that any query string before the rewrite won't get appended.
在Apache的2.4或更高版本可以使用QSD 查询字符串报废标志:
In Apache 2.4 or newer you can use the QSD query string discard flag:
RewriteEngine On
RewriteCond %{QUERY_STRING} x=(.*)
RewriteRule .* http://www.somesite.com/ [R=301,L,QSD]
这篇关于从与htaccess的基础URL删除变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!