Stop query string from being appended to URL

时间:2015-06-15 14:36:19

标签: .htaccess

I have a rewrite rule for my site that passes everything after the domain name as a parameter:

RewriteRule ^([0-9a-zA-Z_=/&\-]+)?$ index.php?page=$1   [L,QSA]

But when going to:

mydomain.co.uk/mypage

..it is appending the query string after the URL (In the browser address bar) like this:

mydomain.co.uk/mypage?page=mypage

I thought it was just Chrome being weird... but it does it in IE aswell.

Has anyone ever had this? Any help would be great I just need it not to append the query string to the end and stay as "mydomain.co.uk/mypage"

1 个答案:

答案 0 :(得分:0)

您可以使用条件检查所请求的文件是否存在。

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) index.php?page=$1   [L,QSA]

我使用htaccess.mwl.be为此请求的网址http://mydomain.co.uk/mypage?page=mypage测试了此代码,并将其重定向到http://mydomain.co.uk/index.php?page=mypage

相关问题