gpt4 book ai didi

.htaccess - 使用 htaccess 删除查询字符串和参数

转载 作者:行者123 更新时间:2023-12-05 07:34:06 24 4
gpt4 key购买 nike

我有一个 php 站点的以下 url,我想使用 htaccess 删除查询字符串和参数。

https://demo.site.com/html/folder/index.php?page=news
https://demo.site.com/html/folder/index.php?page=one-page-layout&header=default&layout=boxed

这样就变成了

https://demo.site.com/html/folder/news
https://demo.site.com/html/folder/one-page-layout

我已经尝试了这里提供的各种解决方案,但都没有用。

这是我的完整 htaccess:

RewriteEngine on
#redirect /html/sandal/index.php?page=pageName to /html/sandal/pageName
RewriteCond %{THE_REQUEST} /html/sandal/(?:index.php)?\?page=([^\s]+) [NC]
RewriteRule ^.+$ /html/sandal/%1? [L,R]
# internally forward /html/sandal/pageName to /html/sandal/index.php?page=pageName

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)/?$ /html/sandal/index.php?page=$1 [QSA,NC,L]

最佳答案

.htaccess 中的 /html/folder 添加以下规则:

RewriteEngine on
#redirect /html/folder/index.php?page=pageName to /html/folder/pageName
RewriteCond %{THE_REQUEST} /html/folder/(?:index.php)?\?page=([^\s]+) [NC]
RewriteRule ^.+$ /html/folder/%1? [L,R]
# internally forward /html/folder/pageName to /html/folder/index.php?page=pageName

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /html/folder/index.php?page=$1 [NC,L]

这会将 /html/folder/pageName 重写为 /html/folder/index.php?page=pageName

关于.htaccess - 使用 htaccess 删除查询字符串和参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50323290/

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