Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add abbreviation of the country in the url address

Status
Not open for further replies.

deuxk

Programmer
Jun 2, 2007
3
CA
Hello,

I try to make a change to my current htaccess for now my url looks like> sitename.com/en/filename.ext
I want to get to have an address resembling this:
sitename.com/ca/​​en/filename.ext (in case the country is Canada and french language)
sitename.com/us/en/filename.ext (in case the country is United State and English language)
sitename.com/eu/en/filename.ext (in case the country is Europe and English language)
sitename.com/en/filename.ext (in case the country is not mentioned and English language)

Here is the current structure of my htaccess
Code:
AddDefaultCharset utf-8
SetEnv CA America/Montreal

Options -Indexes +FollowSymlinks
RewriteEngine On
RewriteBase /

<IfModule mod_rewrite.c>

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule \.(?:css|png|jpe?g|gif)$ - [L]	 #RewriteRule \.(?:css|png|jpe?g|gif|ttf|js)$ - [L]	
	 
RewriteRule (fr|en)/(.*) /$2?language=$1 [NC,L,QSA]

#language, detect and set
RewriteCond %{QUERY_STRING} !(?:^|&)language=[^&]+
RewriteCond %{REQUEST_URI} !^/(?:fr|en)/
RewriteCond %{HTTP:Accept-Language} ^fr [NC]
RewriteRule .* /fr/$1 [L,R=permanent]
						
RewriteCond %{QUERY_STRING} !(?:^|&)language=[^&]+    
RewriteCond %{REQUEST_URI} !^/(?:fr|en)/
RewriteRule .* /en/$1 [L,R=permanent]	
</IfModule>

For now I try lots of things, but nothing happens ... if you have an idea, it would be greatly appreciated!

pleasure
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top