2012-08-16 140 views
0

我的.htaccess不重写干净的URL就像我想要的。它没有按照指示去做,它给了我一个404错误!.htaccess将不会根据需要重写

我想这一点:

http://localhost/somepossiblepath 

被路由到这一点:

http://localhost/index.php?route=somepossiblepath 

目前,这是我的htaccess文件:

RewriteEngine On 

RewriteCond ${REQUEST_FILENAME} !-d 
RewriteCond ${REQUEST_FILENAME} !-f 
RewriteCond ${REQUEST_FILENAME} !-l 

RewriteRule ^/(.+)$ /index.php?route=$1 [QSA,L] 

我有一个当前的脚本测试看看它会不会起作用:

<?php echo $_REQUEST['route'] ?> 

当我输入/index时,它将起作用,但当我输入其他内容时不起作用。

任何帮助?

回答

0

在.htaccess文件中,通过规则正则表达式匹配的字符串的基目录被剥离(/DOCROOT/.htaccess的情况下)。所以^/(.*)$将不匹配。你需要什么,例如:

RewriteEngine On 

RewriteRule ^index\.php - [L] 

RewriteCond ${REQUEST_FILENAME} !-d 
RewriteCond ${REQUEST_FILENAME} !-f 
RewriteCond ${REQUEST_FILENAME} !-l 

RewriteRule ^(.+)$ /index.php?route=$1 [QSA,L] 
+0

你需要做的不仅仅是给一个秃头的答案。 @nonplus可能甚至不会注意到你已经放弃了领先的'/'。我编辑了你的答案,以表明我的意思。 – TerryE 2012-08-16 17:33:55

+0

仍然不会工作:( – snnth 2012-08-18 00:05:43

+0

需要更多信息。 404错误或任何错误。 – user1603541 2012-08-18 06:35:59