I need for a domain to manage languages (en/it/pt/es) plus remove www. and force https
RewriteEngine On # -> www.example.com to example.com RewriteCond %{HTTP_HOST} www.example.com RewriteRule (.*) http://example.com/$1 [L,R=301] # -> http -> https RewriteCond %{SERVER_PORT} 80 RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I don’t know how to make this rewrite rule :
index.php?lg=es -> /es/ and not /es or /es.php and even refuse index.php?lg=es
RewriteRule ^([a-zA-Z0-9]+)/?$ index.php?lg=$1
??
The SEO is bad for my website only english is known by engine and others languages are on the 4th page of result..
Is it the reason why because i’ve got two ways to display url ??
example.com/it/ and example.com/it should not return the same page
Thanks for help.
EDIT (i think all is correct ?? ) : 07 October thanks for all answers :
RewriteEngine On RewriteCond %{HTTP_HOST} ^www.example.com$ [OR] RewriteCond %{SERVER_PORT} 80 [OR] RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://example.com/$1 [R=301,L] RewriteRule ^/?([a-z]{2})$ /$1/ [R=301,NC,L] RewriteRule ^/?([a-z]{2})/$ /index.php?lg=$1 [NC] RewriteCond %{ENV:REDIRECT_STATUS} ^$ RewriteCond %{REQUEST_URI} ^/?index.php$ RewriteCond %{QUERY_STRING} ^lg=([^&]+)(&.*)?$ RewriteRule ^/?index.php$ - [F] ErrorDocument 404 /404.php
Just a question : Is testing if https off really useful (slow connection ?) ? thanks
EDIT 8 February 2018
After months of use there are a lot of 404 errors .
Htaccess need to more simplified.
I just need :
1) www -> non-www
2) http -> https
3) index.php -> example.com
4) redirect index.php?lg=it and index.php?lg=es and index.php?lg=pt
to example.com/it or to example.com/es or to example.com/pt
and if it’s not one of this language -> go to homepage example.com or 404 ?? but Google webmaster will increase 404 error …
I need a very simplify version of htaccess with 3 languages with Rewrite Base in it ? or not ?
here is my htaccess :
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com$ [OR]
RewriteCond %{SERVER_PORT} 80 [OR]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
RewriteRule ^/?([a-z]{2})$ /$1/ [R=301,NC,L]
RewriteRule ^/?([a-z]{2})/$ /index.php?lg=$1 [NC]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_URI} ^/?index.php$
RewriteCond %{QUERY_STRING} ^lg=([^&]+)(&.*)?$
RewriteRule ^/?index.php$ - [F]
ErrorDocument 404 /404.php
Everything is managed in the index.php, is it better to create 3 pages ?
index.php -> redirect to example.com
es.php -> redirect to example.com/es
it.php -> redirect to example.com/it removing .php
Can someone make it ? Thanks
2
Answers
This should work for you as accepted:
I tested this positive an Ubuntu 16.04.03 LTS with Apache 2.4.27
This solution is nice because can be applied to any domain (no hard code names).
Some notes:
Be aware that 4 and 5 have the index.php file in public/ folder…change or remove it if you want.