使用htaccess路由index.php

使用htaccess路由index.php

问题描述:

I am running wamp on win7 just in case. I am trying to route all requests through a route.php to get clean URLs. Below is my htaccess

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI}  !(auth|folder2) [NC]
RewriteCond %{SCRIPT_FILENAME} !-f  
RewriteRule ^(.*) ./route.php?path=$1 [L]

As you can see the rule should apply to all files, and it did when I ran it on my old wamp installation. Now after copying the files to a new system, for some reason, the rule seems to work for all links except index.php. So if I try http://localhost/proj, I get no routing in the new system. Any ideas?

And before anyone asks, yes rewrite_module is on, and the htaccess is being read and executed cause it works for all other links like http://localhost/proj/users and also because if I try putting garbage values in the htaccess it throws a nice 'internal server error'.

我在win7上运行wamp以防万一。 我试图通过 route.php code>路由所有请求以获取干净的URL。 下面是我的htaccess p>

 选项+ FollowSymlinks 
RewriteEngine On 
RewriteCond%{REQUEST_URI}!(auth | folder2)[NC] 
RewriteCond%{SCRIPT_FILENAME}!-f 
RewriteRule  ^(。*)。/ lute.php?path = $ 1 [L] 
  code>  pre> 
 
 

正如您所看到的那样,规则应该适用于所有文件,并且它在 我在旧的wamp安装上运行它。 现在,在将文件复制到新系统之后,由于某种原因,该规则似乎适用于所有链接 strong> index.php code>。 因此,如果我尝试 http:// localhost / proj code>,我在新系统中没有路由。 有什么想法? p>

在有人要求之前,是 rewrite_module code>,并且正在读取和执行 htaccess code>因为它适用于 所有其他链接,如 http:// localhost / proj / users code>,还因为如果我尝试在htaccess中放入垃圾值,它会抛出一个不错的'内部服务器错误'。 p> DIV>

I'm guessing you have an index.php in that folder, and this condition:

RewriteCond %{SCRIPT_FILENAME} !-f  

...tells apache to perform the rewrite only if the file does not exist.

I would suggest or renaming the file, as you'll need that condition to route static assets like images, scripts, etc.

If there is no index.php (or index.htm[l]) in that folder, just define route.php as the default file in that directory. In your .htaccess:

DirectoryIndex route.php index.php index.html index.htm

(Be aware that this will also apply to any sub-directories as well)