Answer the question
In order to leave comments, you need to log in
Redirection without string replacement (mod_rewrite - RewriteRule) how to implement?
Good afternoon!
I am trying to configure the CNC in the apache2/sites-available/domain.ru.conf file for all subdomains for links of the form:
subdomain.domain.ru /somePageName .html → subdomain.domain.ru/?page= somePageName
It is required that the server understand the request as above, and the entered text was saved in the address bar.
STEP 1 (ATTEMPT 165) I
write the directives:
RewriteCond %{REQUEST_URI} !([^/]*)\.html/$
RewriteRule ^/([^/]*)\.html$ /?page=$1 [L]
ServerName domain.ru
ServerAlias *.domain.ru
ServerSignature Off
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.ru [NC]
RewriteRule ^/(.*) http://www.domain.ru/$1 [L,R] # до этого места включительно все работает
# вот, собственно, интересующий блок преобразований
RewriteCond %{HTTP_HOST} ^([a-z0-9_-]+)\.domain\.ru$ [NC]
RewriteRule ^(.*)\/([^/]*)\.html http://%1.domain.ru/?page=$2 [R,L]
# было:
# RewriteCond %{REQUEST_URI} !([^/]*)\.html/$
# RewriteRule ^/([^/]*)\.html$ /?page=$1 [L]
# поменял REQUEST_URI на REQUEST_FILENAME
# и добавил в RewriteRule флаг R
# стало:
RewriteCond %{REQUEST_FILENAME} !([^/]*)\.html/$
RewriteRule ^/([^/]*)\.html$ /?page=$1 [R,L]
Answer the question
In order to leave comments, you need to log in
RewriteCond %{HTTP_HOST} !^www\.domain\.ru [NC]
# if this is ! = not the domain itself with www
RewriteCond %{HTTP_HOST} ^(www\.|).+\.domain\.ru [NC]
# if it is www or without vwww, plus it is 1 or more characters before the main domain, dots are escaped.
RewriteCond %{REQUEST_URI} ^(.+)\.(html|htm)$
# well, I wrote that, you can do it too
RewriteCond %{REQUEST_FILENAME} !-d
# And this is not a directory.
RewriteCond %{REQUEST_FILENAME} !-f
# is not a file.
RewriteCond %{REQUEST_FILENAME} -l
# and not a link, in general it's not a physical object
RewriteRule ^(.*)$ / http://domain.ru/\?page\=%2/? [R=301,L]
# A group with a rewrite gond is not bucks but percentages, the principle is the same, now we substitute the domain in the steering wheel, and most importantly we shield it? this is actually a special character. which by the way we have at the end, it will remove all get parameters.
Naturally, we prescribe the domain explicitly, since we need to change it, and this is not part of the url.
If you want to save the protocol, then the rule will be overgrown with 3 more lines.
ServerName domain.ru
ServerAlias *.domain.ru
ServerSignature Off
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.ru [NC]
RewriteRule ^/(.*) http://www.domain.ru/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?+.+\.domain\.ru$ [NC]
RewriteRule ^/(.*)\.html$ /index.php?page=$1 [L]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question