2013-07-02 100 views
0

我有限制.htaccess的知識,我需要一些幫助。我需要做一些重定向來啓用漂亮的網址。 在本地所有的作品都很好,但它不在另一個開發服務器上工作。顯然,查詢字符串在重定向時丟棄。 我需要這個http://mysite.local/info/permalink/1.htaccess丟失查詢字符串

重定向到這一個http://mysite.local/info?proxy=true&id=1

.htaccess代碼:

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/

#remove /index.php from home url and redirect to root. 
#http://mysite.local/index.php -> http://mysite.local/ 
RewriteCond %{THE_REQUEST} ^.*\/index\.php?\ HTTP/ 
RewriteRule ^(.*)index\.php?$ "/$1" [R=301,L,QSA] 

#pretty url without index.php 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule .* index.php [PT,QSA,L] 

#rewrite to handle some permalink saved on my db. 
#http://mysite.local/info/permalink/1 
#http://mysite.local/info/proxy=true&id=1 
RewriteRule ^([^/]+)/info/([a-zA-Z0-9\-]+)/([0-9]+) /info/?proxy=true&id=$3 [L] 
</IfModule> 

重定向是工作,但查詢字符串不存在。當我的信息模塊上運行var_dump($_GET)我得到一個空數組array(0) {} 我已經嘗試解決不斷變化的

RewriteRule .* index.php [PT,QSA,L]

RewriteRule ^(.*)$ /%{QUERY_STRING} [L]

RewriteRule ^([^/]+)/info/([a-zA-Z0-9\-]+)/([0-9]+) /info/?proxy=true&idobj=$3 [L]

RewriteRule ^([^/]+)/info/([a-zA-Z0-9\-]+)/([0-9]+) /info/?proxy=true&idobj=$3 [QSA,NE,L]

服務器API是CGI/FastCGI的

我應該改變,以確保我的重寫按預期工作和$_GET變量仍然可以訪問什麼? thx預先

回答

1

我不知道你如何設法得到這個正則表達式模式,如:^([^/]+)/info如果你要去的URL是/info/permalink/1

^([^/]+)/info模式表示在URI的/info部分之前有東西,但沒有。另外,在一個htaccess文件中,URI的前導斜槓被剝離了。所以你可能想要這樣的事情:

RewriteRule ^info/([a-zA-Z0-9\-]+)/([0-9]+) /info/?proxy=true&id=$2 [L] 
+0

Thx關於答案。我說過,我有限的.htaccess知識。 在我的本地電腦我的htaccess的作品。如果我使用您的修改,它不起作用。但問題不是我的機器,而是測試服務器。無論如何,在測試服務器中,您的解決方案仍然無法工 – user468891