【发布时间】:2014-03-26 21:14:38
【问题描述】:
我正在尝试重写以下内容
http://example.com/somefile?variable=somevariable
到
index.php?processurl=/somefile?variable=somevariable
我知道我需要使用 [QSA] 来传递变量,所以我在我的 htaccess 中编写了以下内容:
RewriteEngine On
RewriteBase /
RewriteRule ^(.*) index.php?processurl=/$1 [QSA]
但是,这个 RewriteRule 似乎没有传递变量。我得到的只是 index.php?processurl=/somefile
【问题讨论】:
-
尝试将新查询字符串中的 / 更改为 %2F,看看是否有帮助。
processurl=%2F$1等 -
您必须添加
[L](最后一个)标志。试试[QSA,L] -
首先,它会重写为:
index.php?processurl=/somefile&variable=somevariable尽管这无关紧要,因为你永远不会看到它。 第二:“我得到的只是 index.php?processurl=/somefile” 你从哪里得到的? 第三:你试过var_dump($_GET);吗?输出是什么? -
@Steven Second:当我回显
$_GET[processurl]时,我明白了。 第三:输出是array(2) { ["loadurl"]=> string(8) "/somefile" ["variable"]=> string(12) "somevariable" }所以重写器正在正常工作,只是我的php没有占用整个字符串。例如,我怎样才能echoall of$_GET[processurl],而不必$_GET所有单独的变量。感谢您的帮助。 -
好的,我在下面添加了一个解决方案/说明,应该可以解决您的问题(假设我了解您要做什么)。
标签: apache .htaccess mod-rewrite url-rewriting