S
S
Sergey2013-11-23 15:11:00
Apache HTTP Server
Sergey, 2013-11-23 15:11:00

htaccess: why can't the rule work?

There is a site with one entry point. There is a rule in htaccess in which all requests for non-existent files are redirected to index.php. In order not to litter the logs with erroneous requests for statics, I wanted to prohibit this business. Wrote a rule.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} \.(gif|jpg|png|ico|css|js|swf|wav|mp3|less|cur)$ [NC]
RewriteRule .* - [L,R=404]

On the local server, everything works, but on the combat server, this rule is ignored. If you put a 301 redirect instead of a 404 error, then everything works, that is, the rule is correct (I'm not 100% sure). After this rule, there is only this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) index.php [L]

The server is on apache 2.2.24. I don't work with apache very often, so I have to ask for advice.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Kazarinov, 2013-11-24
@serkaz

htaccess rules for static can be ignored if nginx gives the static

P
Par Mactep, 2013-11-24
@parmactep

Try this way:
And here is a cheat sheet for you just in case mod_rewrite cheat sheet

T
truekenny, 2013-11-23
@truekenny

The third line is definitely not a file, so you need to check%{THE_REQUEST}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question