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

时间:2018-05-14 04:52:07

标签: .htaccess

我有一个php网站的以下网址,我想使用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]

1 个答案:

答案 0 :(得分:0)

.htaccess的{​​{1}}中添加以下规则:

/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