W
W
Win32Sector2018-10-07 16:15:16
Apache HTTP Server
Win32Sector, 2018-10-07 16:15:16

How to make RewriteRule one for the main page in apache, another for all other pages?

Good day!
Tell me, please, what am I doing wrong?
At the moment, the following rule is set for all pages of the site:

RewriteCond %{HTTP_ACCEPT} text/html [NC]
RewriteCond %{HTTP_HOST} ^mysqite\.com [NC]
RewriteRule .* path/to/html/my.html [L]

It redirects all requests to my.html.
How to make requests from the main page go to the my-main.html page, and from the rest of the pages to my.html I
tried this, but it does not work. More precisely, requests from the main page go correctly to my-main.html, but from other pages they do not go to my.html.
RewriteCond %{HTTP_ACCEPT} text/html [NC]
RewriteCond %{HTTP_HOST} ^mysqite\.com$ [NC]
RewriteRule ^$ path/to/html/my-main.html [L]

RewriteCond %{HTTP_ACCEPT} text/html [NC]
RewriteCond %{HTTP_HOST} ^mysqite\.com [NC]
RewriteRule ^/(.*) path/to/html/my.html [L]

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2018-10-07
@dodo512

RewriteRule ^/

In this form, it only works in the context of VirtualHost, and in .htaccess the line with which the RewriteRule works does not start with /
httpd.apache.org/docs/2.4/mod/mod_rewrite.html#rew...
In VirtualHost context, The Pattern will initially be matched against the part of the URL after the hostname and port, and before the query string (eg "/app1/index.html"). This is the (%-decoded) URL path.
In per-directory context (Directory and .htaccess), the Pattern is matched against only a partial path, for example a request of "/app1/index.html" may result in comparison against "app1/index.html" or "index .html" depending on where the RewriteRule is defined.

W
Win32Sector, 2018-10-07
@Win32Sector

Udalos will do it like this:

RewriteCond %{HTTP_ACCEPT} text/html [NC]
RewriteCond %{HTTP_HOST} ^mysqite\.com$ [NC]
RewriteRule ^$ path/to/html/my-main.html [L]

RewriteCond %{HTTP_ACCEPT} text/html [NC]
RewriteCond %{HTTP_HOST} ^mysqite\.com [NC]
RewriteRule !^/path/to/html/my-main$ path/to/html/my.html [L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question