0

我在.htaccess文件中使用此代码:

RewriteRule ^([0-9a-zA-Z].+)\.html$ view.php?question=$1 [L,QSA,NC]

它是这样显示的,what-is-your-name.html 但我想这样使用:

what-is-your-name?.html

我该如何使用它?

4

1 回答 1

0

RewriteRule ^([0-9a-zA-Z].+).html$ view.php?question=$1 [L,QSA,NC]

你的名字是什么.html

您将收到$1 what-is-you-name

如果您将 RewriteRule 更改为

RewriteRule ^([0-9a-zA-Z].+)$ view.php?question=$1 [L,QSA,NC]

你叫什么名字?.html

您将收到相同的$1(再次what-is-you-name,没有“?”)

因此,当您放置标志 [QSA] 时,您将收到

view.php?question=what-is-your-name&.html

如果你不想这样做,并且你想在你的 PHP 中收到问号,你应该 urlencode() 它。

那么你的链接应该是:

你叫什么名字%3F.html

并且使用您的第一个 RewriteRule,您的 php 将收到: $_GET['question'] --> "what-is-your-name?"

于 2015-07-16T10:18:54.113 回答