I have a file like
www.domain.com/test.php
I want to write a rule that when ever this is called i am sending an argument to this file but I don't want them to show in the URL I.E. when the above path is in the browser the actual rule should be:
www.domain.com/test.php?state=yes
What should be the .htaccess rule for this? Currently i have in my .htaccess
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^test\.php$ /test.php?view=index [NC,L开发者_如何学Python]
But this is throwing a 500 server error???
I don't get a 500 error, what else do you have in your .htaccess?
Here's what you can use:
RewriteEngine on
RewriteBase /
RewriteRule ^test\.php test.php?view=index [NC,L,QSA]
The QSA flag was missing:
When the replacement URI contains a query string, the default behavior of RewriteRule is to discard the existing query string, and replace it with the newly generated one. Using the [QSA] flag causes the query strings to be combined.
Consider the following rule:
RewriteRule /pages/(.+) /page.php?page=$1 [QSA]
With the [QSA] flag, a request for /pages/123?one=two
will be mapped to /page.php?page=123&one=two
. Without the [QSA] flag, that same request will be mapped to /page.php?page=123
- that is, the existing query string will be discarded.
source: http://httpd.apache.org/docs/current/rewrite/flags.html#flag_qsa
精彩评论