D
D
Den Alex Smith2018-11-09 15:35:58
htaccess
Den Alex Smith, 2018-11-09 15:35:58

RewriteRule for all subdomains, 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:
http:// * .domain.ru/somePageName.html → http:// * .domain.ru/?page= somePageName I write
directives:
RewriteCond %{REQUEST_URI} !([^/]*)\.html/$
RewriteRule ^/([^/]*)\.html$ /?page=$1 [L]
I get results:
subdomain.domain .ru/news.html/?page=news
subdomain.domain.ru/questions.html/?page=questions
What am I doing wrong? Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaliy Orlov, 2018-11-16
@orlov0562

Hello,
if we talk about those directives that you wrote, then you do not need RewriteCond, because the regex in RewriteRule covers it. In the RewriteRule, you need to remove the leading slash and specify the file where the data is transferred.

RewriteEngine On
RewriteRule ^([^/]+)\.html$ index.php?page=$1 [L]

index.php
<?php
print_r($_REQUEST);

Also here ([^/]*) should be a plus, i.e. like this ([^/]+) .
* = zero or more occurrences.
+ = one or more occurrences.
In the case of an asterisk, your regular expression will work on a url like domain.tld/.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question