简体   繁体   中英

routing index.php with htaccess

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM