Question

I have a multilingual website and. Htaccess, which displays all the pages.

I want to redirect (using code 301) asks with RewriteEngine. For example:

site.com?lang=ru => site.com (remove `lang=ru` - Russian only)
site.com/news.html?lang=ru => site.com/news.html

site.com/home.html => site.com (remove `home.html` - only on the main page)
site.com/home.html?lang=ua => site.com/?lang=ua

site.com/rev.html?lang=ua&start=0 => site.com/rev.html?lang=ua (If start = 0, then remove `start=0`)
site.com/rev.html?lang=ua&start=27 => site.com/rev.html?start=27&lang=ua (should be conversely)

and so on many ...

I have very little experience of the redirect. You can help me. How to prepare your htaccess file for Apache to meet this criterion? What to do?

Thanks in advance

Was it helpful?

Solution

Removing lang=ru

RewriteCond %{QUERY_STRING} ^(.*)&?lang=ru(.*)$
RewriteRule ^(.*)$ /$1?%1%2 [L,R=301]

Removing the home.html

RewriteRule ^home.html$ / [L,R=301]

Removing start=0

RewriteCond %{QUERY_STRING} ^(.*)&?start=0(.*)$
RewriteRule ^(.*)$ /$1?%1%2 [L,R=301]

Swapping start=## and a lang=##

RewriteCond %{QUERY_STRING} ^(.*)lang=(.+)&start=([0-9]+)(.*)$
RewriteRule ^(.*)$ /$1?%1start=%3&lang=%2%4 [L,R=301]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top