2013-03-10 98 views
0

我有以下的規則,我的htaccesshtaccess的重寫不通過查詢字符串

RewriteEngine on 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule .+ redirect.php [L] 
RewriteRule ^(.*)\.(?!js|css|png)([^.]*)$ redirect.php [L] 

一切正常,除了一兩件事,查詢字符串完美。
由於某種原因,查詢字符串即消失......

我得到了以下網址myweb.com/subscribe?email=blablabla 在redirect.php我有以下行:

echo $_GET['email']; //should echo the email 

和它不呼應什麼...
*我查了一下,它並重寫redirect.php

任何想法,爲什麼,以及如何解決它?

+2

可能重複http://stackoverflow.com/questions/4071155/htaccess-rewriterule-to- preserve-get-url-parameters) – mario 2013-03-10 14:56:38

+0

QSA標誌沒有工作。我嘗試了一切...... – Ron 2013-03-10 15:03:40

+0

請注意你有兩條規則,使用'QSA',這是兩個正確的答案。 – Wrikken 2013-03-10 15:44:31

回答

0

通過以下步驟解決它:

  1. 我沒有想重寫CSS,JS,PNG等文件,所以在我的最後一條規則是被列入正則表達式 - 我分裂了。
  2. 添加了[QSA]標誌2條最後規則
  3. 新增RewriteCond %{REQUEST_FILENAME} !-f
  4. 更改RewriteCond %{REQUEST_FILENAME} -dRewriteCond %{REQUEST_FILENAME} !-d

這是它的外觀:

RewriteEngine on 
RewriteBase/
RewriteRule \.(ico|css|png|js|txt|xml)$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule .+ redirect.php [QSA,L] 
RewriteRule ^(.*)$ redirect.php [QSA,L] 
[重寫規則的.htaccess保護GET URL參數(中