DirectoryIndex index index.html DirectorySlash off Options -Indexes -MultiViews # Rules # site.com/ # site.com/index -> site.com # site.com -> site.com/ # site.com/file/ -> site.com/file.html # site.com/file -> site.com/file.html # site.com/dir/file ->site.com/dir/file.html # site.com/dir/file/ -> site.com/dir/file.html # no ending slashes RewriteEngine On RewriteBase / RewriteCond %{REQUEST_URI} \.(css|jpg|gif|png|zip|rar|doc|xls|js|tif|tiff|docx|xlsx|ico)$|test\.php$ RewriteRule ^(.*)$ $1 [L,QSA] # nothing to do there in subrequests RewriteCond %{ENV:NS} !=1 RewriteCond %{IS_SUBREQ} =true RewriteRule (.*) $1 [L,QSA] #do NS=0? RewriteCond %{REQUEST_URI} ^/index$ [OR] RewriteCond %{REQUEST_URI} ^/index[.]+(\w+)$ RewriteRule . / [R=301,L] # remove trailing slashes # if want external redirect use correct external redir [R=301,L] or [R=301] for correct internal or simple redir [L] RewriteCond %{REQUEST_URI} !^/$ RewriteCond %{REQUEST_URI} (.*)/$ RewriteRule . %1.html [R=301,L,E=NS:1,QSA] # if whants .html endings RewriteCond %{REQUEST_URI} !^(.+)\.(html|php)$ RewriteRule . %{REQUEST_URI}.html [R=301,L] # fix multidots in endings (missed language) index..html instead of index.en.html RewriteCond %{REQUEST_URI} ^(.+)\.\.+(\w+)$ RewriteRule . %1.%2 [R=301,L] # otherways #RewriteCond %{REQUEST_URI} (.+)\.(html|php)$ # RewriteRule . %1 [R=301,L] # any php filename in root dir # this makes secure loses RewriteCond %{REQUEST_URI} ^[\w\-.]+$ RewriteCond %{REQUEST_FILENAME} (.*)\.(html|php)$ RewriteCond %1.php -s [OR] RewriteCond %1.html -s RewriteRule . %1.%2 [L,QSA] RewriteRule (.*) entry.php?URI=$1 [L,QSA] #
DirectoryIndex index index.html DirectorySlash off Options -Indexes -MultiViews
RewriteEngine On RewriteBase / RewriteCond %{REQUEST_URI} \.(css|jpg|gif|png|zip|rar|doc|xls|js|tif|tiff|docx|xlsx|ico)$|test\.php$ RewriteRule ^(.*)$ $1 [L,QSA]
|test\.php$
is made for various test files, but in the production this case should be removed. # nothing to do there in subrequests RewriteCond %{ENV:NS} !=1 RewriteCond %{IS_SUBREQ} =true RewriteRule (.*) $1 [L,QSA] #do NS=0?
RewriteCond %{REQUEST_URI} ^/index$ [OR] RewriteCond %{REQUEST_URI} ^/index[.]+(\w+)$ RewriteRule . / [R=301,L]
# remove trailing slashes # if want external redirect use correct external redir [R=301,L] or [R=301] for correct internal or simple redir [L] RewriteCond %{REQUEST_URI} !^/$ RewriteCond %{REQUEST_URI} (.*)/$ RewriteRule . %1.html [R=301,L,E=NS:1,QSA]
[R=301,L]
, if internal (change the url in the browser string), then [R=301]
or [L]
# if whants .html endings RewriteCond %{REQUEST_URI} !^(.+)\.(html|php)$ RewriteRule . %{REQUEST_URI}.html [R=301,L]
# fix multidots in endings (missed language) index..html instead of index.en.html RewriteCond %{REQUEST_URI} ^(.+)\.\.+(\w+)$ RewriteRule . %1.%2 [R=301,L]
# any php filename in root dir # this makes secure loses RewriteCond %{REQUEST_URI} ^[\w\-.]+$ RewriteCond %{REQUEST_FILENAME} (.*)\.(html|php)$ RewriteCond %1.php -s [OR] RewriteCond %1.html -s RewriteRule . %1.%2 [L,QSA]
RewriteRule (.*) entry.php?URI=$1 [L,QSA]
E=NS:1
sets the environment variable NS to 1 — needed to define a subquery (the subquery created by the transformation rules by “agreement”, and not by any other subquery).Source: https://habr.com/ru/post/141424/
All Articles