Y
Y
Yuukari2019-08-12 23:09:55
htaccess
Yuukari, 2019-08-12 23:09:55

How to implement redirects with exceptions in .htaccess?

Hello. I have a .htaccess file configured like this:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} -s [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [NC,L] 
RewriteRule ^.*$ index.php [NC,L]

It is required to me that any request coming to a site, has been processed through index.php. That is, upon transition, for example, to localhost/users/4815, the server will process it through index.php, and pass the value "/users/4815" to the $_SERVER["REQUEST_URI"] variable.
But here a problem arises. I also need to add exceptions to some urls, such as localhost/assets, so that the server handles requests for this directory and its contents as normal, without redirecting them to index.php. Tried a bunch of options - nothing works.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2019-08-13
@dodo512

RewriteEngine On 
RewriteCond %{REQUEST_URI} ^/assets/ [OR]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^ index.php [L]

V
Viktor Taran, 2019-08-13
@shambler81

RewriteCond %{REQUEST_URI} !^/assets/
! - denial

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question