Apache URL 重写:删除index.php 和查询字符串

问题描述 投票:0回答:1

我有一个链接,例如:

https://test.com/index.php?code=myko

我想把它变成:

https://test.com/myko

迄今为止我最好的尝试是:

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

到目前为止我能看到的所有答案都涉及仅删除index.php,或仅以某种方式处理查询字符串,上面是迄今为止我能看到的最接近的答案,但无法正常工作。

在上面的例子中,它添加了

index.php
作为代码。我尝试过 $0、$1 等。

请通过

.htaccess
协助更改此设置。

php apache .htaccess url-rewriting
1个回答
0
投票

我已经找到答案了。我需要在末尾的方括号中添加 QSL。所以代替:

RewriteRule ^(.*)$ index.php?code=$1 [L]

我必须做:

RewriteRule ^(.*)$ index.php?code=$1 [QSA,L]
© www.soinside.com 2019 - 2024. All rights reserved.