2015-09-27 99 views
0

這是我的.htaccess代碼乾淨的網址重寫。htaccess多個參數重寫乾淨的網址

Options +FollowSymLinks -MultiViews 
# Turn mod_rewrite on 
RewriteEngine On 
RewriteBase/

RewriteCond %{THE_REQUEST} ^[a-zA-Z]{3,}\s/+index\.php\?bank=([^\s&]+) [NC] 
RewriteRule^%1%2%3%4? [R=301,L] 
RewriteRule ^([^/]+)/?$ index.php?bank=$1$2$3$4 [L,QSA] 

此代碼適用於url中的單個參數。例如,它rewrites

http://bankifscodes.in/pragathi-krishna-gramin-bank-ifsc-code/
http://bankifscodes.in/index.php?bank=pragathi-krishna-gramin-bank-ifsc-code/

但是,當我試圖通過在url多個參數,我的一切都是errors

我需要一個像
http://bankifscodes.in/pragathi-krishna-gramin-bank-ifsc-code/karnataka/bidar而不是http://bankifscodes.in/index.php?bank=pragathi-krishna-gramin-bank-ifsc-code/karnataka/bidar

一個網址我怎樣才能改變我的代碼通過多個網址。

+0

使用臨時302重定向的發展,而不是永久的301個重定向。 301重定向適用於網站永久移動的情況,例如更改域名。但是,當涉及到URL重寫時,即使在生產環境中,您也會發現不斷移動的東西,而301重定向會因瀏覽器緩存而陷入麻煩。嘗試切換到302重定向,並繼續在不具有重定向緩存的其他瀏覽器中測試,或者從301重定向中清除瀏覽器緩存。 – Ultimater

回答

2

您重定向邏輯可以大大簡化爲:

Options +FollowSymLinks -MultiViews 
RewriteEngine On 
RewriteBase/

#If a request does not match an existing directory 
    RewriteCond %{REQUEST_FILENAME} !-d 
#And does not match an existing file 
    RewriteCond %{REQUEST_FILENAME} !-f 
#then rewrite all requests to index.php 
    RewriteRule ^(.*)/?$ index.php?bank=$1 [L,QSA] 
+0

哇!它最終工作。感謝您的答覆。 – paranjothi