dongye6377 2014-01-09 00:21
浏览 71
已采纳

使用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'.

  • 写回答

1条回答 默认 最新

  • dpvomqeu396484 2014-01-09 00:29
    关注

    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)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?