【发布时间】:2021-12-17 23:53:13
【问题描述】:
我正在尝试了解如何实现以下重写规则。
来自
https://localhost/site/?page=place&place=west
https://localhost/site/?page=location&location=cityname
到
https://localhost/site/place/west
https://localhost/site/location/city
我可以改变 https://localhost/site/?page=place 到 https://localhost/site/place 但不是上面提到的另一个附加查询。
htaccess
RewriteEngine On
#Redirect /site/?page=foobar to /site/foobar
RewriteCond %{THE_REQUEST} /site/(?:index\.php)?\?page=(.+)\sHTTP [NC]
RewriteRule ^ /site/%1? [L,R]
# Internally rewrite new path to the original one
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?:site/)?(.+)/?$ /site/?page=$1 [L,QSA]
上面的 htaccess 适用于我也需要的以下内容。
https://localhost/site/place
https://localhost/site/about
https://localhost/site/contact
【问题讨论】:
标签: apache .htaccess mod-rewrite friendly-url url-rewrite-module