PHP & Apache Mod rewrite: search?keyword
these are the rewrite rules I normally use for clean urls,
RewriteRule ^([a-zA-Z0-9\-]+)/?$ index.php?pg_url=$1 [L,QSA]
RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/?$ index.php?pg_url=$2开发者_如何学JAVA [L,QSA]
they will accept requested urls such as,
mysite/home
mysite/portfolio/photograhy
but how can I set the rewrite rule for seaching such as,
mysite/search?photograhy
mysite/search?painting
I tried with this one below,
RewriteRule ^search?([a-zA-Z0-9\-]+)/?$ index.php?pg_url=search&keyword=$1[L,QSA]
they keyword seach won't appear correctly, but I will get this below whatever I search for,
echo $_REQUEST['keyword'];
h[L,QSA] // result
thanks.
You need to use a RewriteCond for the Query String, a la:
RewriteCond %{QUERY_STRING} ^keyword=([a-zA-Z0-9\-]+)$
You'll need to adjust your query to do something like ?keyword=photography
Here's some reading on the subject: http://wiki.apache.org/httpd/RewriteQueryString
精彩评论