gpt4 book ai didi

apache - URL 重写 - 多重查询

转载 作者:行者123 更新时间:2023-12-04 13:05:15 25 4
gpt4 key购买 nike

我正在尝试了解如何实现以下重写规则。

来自

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 但不使用上面提到的另一个附加查询。

访问权限

 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

最佳答案

根据您显示的尝试,请尝试遵循 htaccess 规则文件。确保在测试您的 URL 之前清除您的浏览器缓存。新规则与您现有的规则相结合。

RewriteEngine ON
RewriteBase /site/
##New rules from here......
RewriteCond %{THE_REQUEST} \s/site/?\?page=([^&]*)&place=([^&]*)\s [NC]
RewriteRule ^ /site/%1/%2? [R=301,L]

# Internally rewrite new path to the original one
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^site/([^/]*)/(.*)/?$ index.php?page=$1&location=$2 [NC,QSA,L]

关于apache - URL 重写 - 多重查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69827605/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com