简体   繁体   中英

.htaccess redirect issue with language

I want to make my .htaccess file redirect to https by default but, I also want to use the language directory.

eg I want the following redirects:

  1. http://example.org -> https://example.org/en/Home
  2. www.example.org -> https://example.org/en/Home
  3. example.org/test?test=test -> https://example.org/en/test?test=test

Note, en should be the browser default language or the cookie 'Language' when set. The cookie should rank above the browser default

So, What my .htaccess-file looks like at the moment is:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

RewriteCond %{HTTP_HOST} ^www\.example\.org
RewriteRule ^(.*)$ "https\:\/\/example\.org\/$1" [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?$ "/Home" [R=301,L]
RewriteRule ^([a-zA-Z]{2})/?$ /$1/Home [R=301,QSA,L]
RewriteRule ^([a-zA-Z]{2})/(.+)?/?$ $2/?Language=$1 [L,QSA]

RewriteCond %{HTTP_USER_AGENT} libwww-perl.* 
RewriteRule .* ? [F,L,QSA]

ErrorDocument 404 /404/
ErrorDocument 500 /500/

Try with below conditions, I didn't tried for now.

RewriteCond %{HTTP_HOST} ^www [OR]
RewriteRule %{REQUEST_URI} ^(.+?)$
RewriteRule ^ https://example.org/en%{REQUEST_URI} [R=301,L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM