skip to Main Content

I need to redirect all url’s that contain the parameter ?lang= to my base url.

For example: If www.example.com/?lang=ru redirect to www.example.com.

I have tried with RedirectMatch but it’s not working.

Thanks!!!

2

Answers


  1. Using Regular Expressions

    If you want to use a Regular Expression to redirect something, use the RedirectMatchdirective:

    RedirectMatch “^/lang=ru?.html/?$” “http://example.com/newfile.php

    Don’t forget have mod_rewrite on in your apache configuration, and other configuration neccessary for enable your htaccess file.

    Login or Signup to reply.
  2. The Redirect* directives do not handle the query string so you need to use URL rewriting instead.

    RewriteEngine on
    
    # if the query string contains a parameter called "lang"
    RewriteCond %{QUERY_STRING} (?:^|&)lang=
    # then redirect (permanently) to /
    RewriteRule ^ / [L,R=permanent]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search