2012-06-07 84 views
1

我有一个重定向所有URL的index.php文件与路径查询字符串参数.htaccess文件:mod_rewrite的与查询字符串在漂亮的URL

# Enable Mod_rewrite 
RewriteEngine on 

# Redirect pretty URLs to the index file 
RewriteRule ^([\w\/\-]+)/?$ index.php?route=$1 

这个伟大工程,具有URL的异常,并查询它们中的字符串。例如,我有一个表单重定向回到登录屏幕,出现错误代码(/admin/login?error=1)。显然,问题是,$_GET[error]参数永远不会传递给主脚本。

我将如何获得传递给脚本的这些参数?

回答

7

只需添加[QSA]作为一个标志:

“qsappend | QSA”(查询字符串追加)此标记强制重写 引擎替换字符串的查询字符串的一部分追加到 现有的字符串,而不是取代它。当您想要 通过重写规则将更多数据添加到查询字符串时使用此选项。

RewriteRule ^([\w\/\-]+)/?$ index.php?route=$1 [QSA]

+0

非常酷,不知道那个标志存在。谢谢:) –

+0

你只是打败了我劳伦斯:)有一个upvote。 –

2

设置标志QSA - 查询字符串附加

# Enable Mod_rewrite 
RewriteEngine on 

# Redirect pretty URLs to the index file 
RewriteRule ^([\w\/\-]+)/?$ index.php?route=$1 [QSA] 

(我所做的只是添加[QSA])

Apache的mod_rewrite的文档中有更多关于标志。

+0

非常感谢! :) –

3

这是我的标准mod_rewrite的条目(改变你的问题)。我将它添加到任何潜在的疼痛中,例如图像&包括。它重定向除了现有文件以外的所有内容。

<IfModule mod_rewrite.c> 
    Options +FollowSymlinks 
    RewriteEngine On 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^([\w\/\-]+)/?$ index.php?route=$1 [QSA] 
</IfModule> 
+0

感谢您的帮助片段:) –

+0

这正是我一直在寻找的。谢谢。 – Jeff