如何在htaccess文件中为以下功能编写重写规则。
www.hostname.com/store.php?city=cityname -> www.hostname.com/cityname
答案 0 :(得分:0)
将此代码放入DOCUMENT_ROOT/.htaccess
文件中:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+store\.php?city=([^&\s]+) [NC]
RewriteRule ^ %1? [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ store.php?city=$1 [QSA,L]