U
U
utf2012-07-05 19:15:47
Apache HTTP Server
utf, 2012-07-05 19:15:47

What is wrong with my rules for mod_rewrite?

For some reason, these rules do not work correctly on hosting

RewriteEngine On
RewriteBase /

# Exclude /assets and /manager directories and images from rewrite rules
RewriteRule ^(manager|assets)/*$ - [L]
RewriteRule \.(js|ico|gif|jpg|png|css|xml|phps|mp3|ogg|avi|mpg|acc|swf|jpeg)$ - [L]

# For Friendly URLs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/assets/cacheimg
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

For some reason, when requesting a non-existent file in the /assets/cacheimg folder, index.php?q=… is launched,
although the standard server 404 page should be issued.
I checked it at myself and on another hosting - everything is OK.
Apache v2.2 on all servers.
Can you please tell me where could be the error?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
K
karenishe, 2012-07-05
@karenishe

Apparently .htaccess is not in document_root? Write the full path in the line with RewriteCond %{REQUEST_URI} !^/assets/cacheimg

A
Andrey Burov, 2012-07-05
@BuriK666

add to /assets/cacheimg/.htaccess
RewriteEngine Off
this can be if VirtualDocumentRoot is used or there are other mod_rewrite rules

C
charliez, 2012-07-05
@charliez

and in technical support of a hoster if to address?

A
AHTOH, 2012-07-06
@AHTHOH

Doesn't work, because RewriteCond only works with the rule following it, to combine several RewriteConds, you need to put [OR] at the end of the line. And specify what to do according to this directive.
I guess this will work:
# For Friendly URLs
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteCond %{REQUEST_URI} !^/assets/cacheimg
RewriteRule .* - [R =404]
RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question