RewriteRule RewriteCond in. htaccess
The situation is as follows. I found an instruction on the Internet .htaccess using mod_rewrite to "tie" all the questions to a single file index.php
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ [NC,L]
RewriteRule ^.*$ index.php [NC,L]
It is necessary: to exclude files of types .css and .js from this construction. I myself am working with the htaccess file at this level for the first time (AddDefaultCharset does not count)
Literally from the words of the author: *This entry means literally the following: if the requested URL is not a file, it is not a symbolic link and is not a directory, then replace the virtual address with a file index.php. At the same time, the PHP superglobal variable
**$_SERVER['REQUEST_URI']**
It will contain exactly the requested virtual address.*
My reasoning:
- RewriteCond-generates a specific rule that will be used to make a redirect
- %{REQUEST_FILENAME} - the request string itself
- -s, -l, -d-special parameters that check for the" non-zero " character of the file. a link, a directory. I.e., if the query string points to an existing folder or file, then there will be no redirect
- The last 2 lines-perform the redirect itself
Explain to me how to write a rule to remove css and js files from the redirect.
Request: messages like google to help, search the internet for do not write. I need a human explanation. i.e. a complete parsing of such a rule. I don't need to stupidly copy-paste, but understand the logic of the work, so that there are fewer questions in the future.
Thank you in advance to all who responded
1 answers
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Explanation: If this is not a symlink [and] not a file [and] not a directory, then a virtual redirect is made to /index.php
Update
Using a whitelist.
RewriteEngine on
RewriteCond %{REQUEST_URI} \.(?!css$|js$|jpeg$|jpg$|png$|gif$|ico$|font$|map$)[^.]+$ [NC]
RewriteCond %{REQUEST_URI} !robots\.txt$
RewriteRule . /index.php [L]
Explanation: If these are not files with the extensions css, js,... [and] not the file robots.txt
, then a virtual redirect is made to /index.php
.