Search code examples
.htaccesshttp-redirectlang

Create ?lang=ua in htaccess (homepage)


I have. Htaccess, which displays only the main page and language ?lang=ua style.

I want to redirect (using code 301) asks site.com to site.com/?lang=ua with RewriteEngine.

site.com => site.com/?lang=ua

I tried this:

    Redirect 301 ^$ http://site.com/?lang=ua
    or
    RewriteRule ^(.*)$ http://site.com/?lang=ua [L]


Displays error "Wrong redirect to a page"

But still not working! How can I do this?

Thanks in advance


Solution

  • You can get rid of the "^" and "$" in Redirect, it doesn't take a regular expression to match. This will do:

    Redirect 301 / http://site.com/?lang=ua
    

    EDIT: Now that I'm thinking about it, this will loop indefinitely because the query string isn't being checked. What you need is this:

    RewriteCond %{QUERY_STRING} !(^|&)lang=ua($|&)
    RewriteRule ^$ http://site.com/?lang=ua [L,R]