[Answered ]-Overwrite the url in .htaccess file for django

2👍

The first thing you need to do is go through all of your code and change your login links to look like:

www.abc.com/login/es

It’ll save you an extra connection and redirect.

Then you need rules in your htaccess file in the www.abc.com document root to redirect the client when the request is made for /login/?lang=something to the nicer looking URL:

RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD)\ /login/?\?lang=([^&\ ]+)
RewriteRule ^ /login/%2? [L,R=301]

Then you need rules to internally rewrite the nicer looking URL back to the one that has the query string:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?login/(.*)$ /login/?lang=$1 [L]

If the base URI has changed (from say, /login to /login/es), you may need to include a base URI in your login page so that relative links will still resolve correctly. You can do this by adding this tag in your page’s header:

<base href="/">

Leave a comment