2017-07-18 150 views
0

我有一個已經遷移到新平臺的應用程序。任務是相似的,我想重定向GET參數到一個目錄。例如Apache .htaccess將目錄重寫爲目錄

http://gallery/index.php?gal=ABC => http://photos/gal/ABC 
    and 
http://gallery/?gal=DEF   => http://photos/gal/DEF 

並且不被逮住的任何它重定向到http://photos

我已經試過

RewriteEngine on 
RewriteCond %{QUERY_STRING} ^(\w+)=(\w+)$ 
RewriteRule ^(/index.php)$ /%1/%2? 

但是我得到的是一個404,沒有重定向。同樣,我已經試過

RedirectMatch ^/index\.php\?=gal(.*) http://photos/gal/$1 

,但我無法在原來的URL逃離?

什麼是正確的方式去做這件事?

回答

2
RewriteCond %{QUERY_STRING} ^(.+)=(.+)$ 
RewriteRule ^index.php$ http://photos %1/%2? [L,NC,R=301] 
+0

這個可以清楚地看到 – vincenth520

+0

不得不修復'照片%1'之間的額外空間,但除此之外一切都很好!謝謝你的幫助! – SteppingHat

+0

不客氣,請接受此答案。謝謝 – vincenth520

1

您的訂單被倒過來。重寫它在你的面前

RewriteRule /(.+)\/(.+) index.php?$1=$2

+0

似乎並沒有爲我工作。什麼都沒發生。我可以確認.htaccess文件正在工作,因爲輸入'RedirectMatch /(.+)http:// photos/$ 1'可以很好地路由'http://gallery/index.php?gal = ABC''=>'' http:// photos /?gal = ABC' – SteppingHat

+0

你試試這個'RewriteRule /(.+)\/(.+)http://gallery/index.php?$ 1 = $ 2' – vincenth520

+0

仍然沒有任何內容:/ – SteppingHat