.htaccess 删除网址中的问号

2023-12-10

我有一个网站,其网址中有一个我想要重写的查询字符串。网址是domain.com/profile.php?user=sven我希望它重定向到domain.com/profile/user/sven.

我创建了一个 htaccess 文件,其规则如下:

RewriteEngine On
RewriteRule ^/?user/([^/]+)/?$ profile.php?user=$1 [L,QSA]
RewriteCond %{QUERY_STRING} ^user=([A-Za-z0-9\-\_]+)$
RewriteRule ^profile\.php$ domain.com/user/%1?/  [L,R=301]

这是可行的,但它重定向到的网址是:domain.com/user/sven?/

我的问题是,我可以删除?在网址中?


将您的 htaccess 更新为以下内容,

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?profile/(.*?)/?$ /profile.php?user=$1 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /profile\.php\?user=([^]+)
RewriteRule ^/?profile\.php$ /users/%1? [L,R=301]
</IfModule>

我希望这有帮助。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

.htaccess 删除网址中的问号 的相关文章