.htaccess 查询字符串htaccess重写

vawmfj5a  于 2022-11-16  发布在  其他
关注(0)|答案(4)|浏览(162)

好吧,我很新,我真的很感激一些帮助,谢谢!
我怎样才能在.htaccess中正确地重写这个?
所以我在我的url中有一个查询字符串:

/?url=contact

我只想删除查询字符串

/contact

帮助?我搜索谷歌,我现在正在学习语法,但事实仍然是..我还不知道如何做到这一点。感谢所有

2ic8powd

2ic8powd1#

这就是我的解决方案:
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]

6qftjkof

6qftjkof2#

试试看:

RewriteEngine On
RewriteRule ^(.*)$ /index.php?url=$1 [L]

对于您站点上的用户,他们将看到并导航到以下内容:

http://example.com/contact

但真实的的页面应该是这样的:

http://example.com/index.php?url=contact

该位[L]告诉服务器这是重写规则的最后一行并停止。

azpvetkf

azpvetkf3#

RewriteCond %{QUERY_STRING} url=(.*)
RewriteRule index.html  %1

(or如果它不是index.html、index.php或任何其他文件)
您需要捕获RewriteRule通常不查看的查询字符串,并使用%1反向引用,而不是像在RewriteRule的捕获中那样使用$1

qzlgjiam

qzlgjiam4#

在此之前:https://example.com/index.php?user=robert

RewriteEngine On
RewriteRule ^user/([^/]+)?$ index.php?user=$1 [L,QSA]

在以下位置之后:https://example.com/user/robert

相关问题