简体   繁体   中英

rewritecond not working for existing files

I have a problem with mod rewrite apache seems to ignore the rewrite cond.

The rewrite rule is working as all my pages are working but the problem is with resources like css, imgs and js. In my html I use "href=assets/css/style.css" which is an existing file but ii am redirected on my index.php...

Is there something i did wrong ?

here is my vhost config

 <VirtualHost *:*> ServerAdmin me@local.loc DocumentRoot "c:/wamp/www/Covoiturage" ServerName covoiturage.loc ErrorLog "logs/covoiturage-error.log" CustomLog "logs/covoiturage-access.log" combined <directory c:/wamp/www/covoiturage/> Allow from all AllowOverride all </directory> </VirtualHost> 

here is my htaccess :

 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)/$ /$1 [R=301,L] RewriteRule ^ index.php [L] 

You are adding RewriteCond to wrong RewriteRule . RewriteCond only in effect to very next RewriteRule . Try this code:

RewriteEngine On

## Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [R=302,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]

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