S
S
Stim7772017-02-07 01:24:42
htaccess
Stim777, 2017-02-07 01:24:42

Setting htaccess to redirect and reverse url substitution?

Hello!
Faced the need to implement the following in htaccess:

  • redirect when requesting site.ru/index.php?sitemap=xml to the page site.ru/sitemap.xml
  • url substitution when site.ru/sitemap.xml is open, the request should process the script site.ru/index.php?sitemap=xml

separately, both points work, but together they cause a circular redirect ... how can this be fixed or implemented more correctly?
here are the codes:
RewriteRule ^sitemap.xml$ /index.php?sitemap=xml [L]

RewriteCond %{QUERY_STRING} ^sitemap=xml
RewriteRule (.*) http://site.ru/sitemap.xml? [R=301,L]

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Viktor Taran, 2017-02-07
@Stim777

! - denial

RewriteCond  %{QUERY_STRING} (^|&)sitemap\=xml($|&)  
(так будет корректней )
RewriteCond  %{REQUEST_URI} !sitemap\.xml$ 
Если не сайтмап
RewriteRule правило

V
Vitaliy Orlov, 2017-02-07
@orlov0562

most likely, you just need to swap them, i.e. like this:

RewriteCond %{QUERY_STRING} ^sitemap=xml
RewriteRule ^index\.php$ http://site.ru/sitemap.xml [R=301,L]

RewriteRule ^sitemap\.xml$ /index.php?sitemap=xml [L]  ## тут должен быть только L, без R

and make sure there are no other redirects, i.e. For the duration of the test, leave only these lines.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question