2013-04-23 22 views
0

如果我使用htaccess的代码:htaccess的规则运作,而不是在应用到同一目录

RewriteRule ^test/(.*)/?$ /taxis/index.php?location=$1 [L,QSA,NC,R] 

和导航链接:

http://test.co.uk/test/abcde

htaccess的作品和转让我到: http://test.co.uk/taxis/index.php?location=abcde

但是,我想改变重写规则,使其适用于相同目录:

^taxis/(.*)/?$ /taxis/index.php?location=$1 [L,QSA,NC,R] 

但后来当我浏览到该链接:

http://test.co.uk/taxis/abcde

链接无法正常工作和生产:

http://test.co.uk/taxis/index.php?location=index.php&location=index.php&location=index.php&location=index.php&location=index.php&location=index.php&location=index.php&location=index.php&location=index.php&location=index.php&location=index.php&location=index.php&location=index.php&location=index.php&location=index.php&location=index.php&location=index.php&location=index.php&location=index.php&location=index.php&location=abcde 

你知道我可以调整这给我:

http://test.co.uk/taxis/index.php?location=abcde

回答

1

如果URI已指向资源,或者只是排除规则的目标,则需要重写规则之前的条件告知它不要重写。重写引擎不断循环所有规则,直到URI停止更改。

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^taxis/(.*)/?$ /taxis/index.php?location=$1 [L,QSA,NC,R] 

意思是:“如果请求不是现有文件,请求不是现有目录,应用规则”

或排除规则的目标:

RewriteCond %{REQUEST_URI} !^/taxis/index\.php$ 
RewriteRule ^taxis/(.*)/?$ /taxis/index.php?location=$1 [L,QSA,NC,R] 
+0

非常感谢你,乔恩,我一直在这一整天工作,现在它已完成和工作。我没有意识到重写引擎会一遍又一遍地循环。 – scott 2013-04-23 19:13:42

相关问题