E
E
Elena2018-09-14 15:16:48
Apache HTTP Server
Elena, 2018-09-14 15:16:48

How to properly rewrite in htaccess?

Good afternoon! I'm trying to translate the site to new urls.
You need to do redirects like

  • mydomain.ru/pages/about -> mydomain.ru/about
  • mydomain.ru/news.php -> mydomain.ru/news
  • mydomain.ru/pages/articles/{id}-> mydomain.ru/articles/somename

at the same time, for all requests, there is an internal redirect to the address mydomain.ru/index.php?query={uri} I
made the first two types through htaccess, the third type is redirected in the script , I
wrote the following rules for htaccess:
Redirect 301 /news.php /news
Redirect 301 /pages/about /about

<IfModule mod_rewrite.c>
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/pages/about
  RewriteCond %{REQUEST_URI} !=/pages/articles
  RewriteCond %{REQUEST_URI} !=^/pages/articles/(*)$
  RewriteRule ^(.*)$ index.php?query=$1 [QSA,L]
</IfModule>

added the conditions RewriteCond %{REQUEST_URI} != because the error "The site has redirected too many times" appeared.
But the RewriteCond %{REQUEST_URI} !=^/pages/articles/(.*)$ condition doesn't work. The same error occurs. Did I write the condition wrong? Or should that moment be handled differently?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2018-09-15
@lenk0belk0

RewriteRule ^pages/articles$ /articles [R=301,L]
RewriteRule ^pages/about$    /about    [R=301,L]
RewriteRule ^news\.php$      /news     [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?query=$1 [QSA,L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question