2011-12-02 69 views
0

我在我的.htaccess以下规则:的Apache的环境变量没有mod_rewrite的规则设定

<IfModule mod_rewrite.c> 
    RewriteEngine on 

    RewriteCond $1 !^index\.php$ 
    RewriteRule ^(.*)$ index.php?q=$1 [L] 
</IfModule> 

此查询字符串值q设置为请求URI(就是那个索引之前剥离前述任一目录.php驻留在)。例如:http://localhost/framework/testingq=testing

我想改变这个,以便设置一个查询字符串,而不是设置一个环境变量。我曾尝试以下,但它不工作(环境VAR不被设置):

<IfModule mod_rewrite.c> 
    RewriteEngine on 

    RewriteCond $1 !^index\.php$ 
    RewriteRule ^(.*)$ index.php [ENV=request:$1,L] 
</IfModule> 

奇怪的是,环境VAR将设置如果请求与index.php文件开始,例如:http://localhost/framework/index.php/testingq=index.php/testing

回答

2

使用PATH_INFO(按照@chrono的建议)和稍微不同的mod_rewrite规则我已经得到了所需的东西!

修改的.htaccess:

<IfModule mod_rewrite.c> 
    RewriteEngine on 

    RewriteCond $1 !^index\.php 
    RewriteRule ^(.*)$ index.php/$1 [L] 
</IfModule> 
+0

你可以检查你的答案现在有效;) –

+0

我想;它回答了我问的问题,但它不适用于别名的URL(共享ssl)。我的目标是不必在我的PHP中指定一个基本的URL。 –

+0

这么好,错......修改你的问题,或检查这个有效,也许问另一个? –

0

我想,你实际上寻找的是PATH_INFO - 如下所述:What exactly is PATH_INFO in PHP?

无需推倒重来,除非有一些其他的原因。

+0

这个作品就像目前的情况;只有当url以index.php开头时才会被设置。我试图让apache env var被设置为任何请求。 –

+0

我现在已经开始使用您提供的建议了,谢谢! downvote道歉,我窃听了我手机上的错误箭头,直到现在才注意到。 –