2015-09-27 92 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