Link to home
Start Free TrialLog in
Avatar of ellandrd
ellandrdFlag for Ireland

asked on

uppercase first segment of url using HTACCESS

I need to change the first segment of my URL to uppercase but it isn't working.  All other URL segments should remain lowercase.

example:

http://www.domain.com/en/ should become http://www.domain.com/EN/
http://www.domain.com/en/home/ should become http://www.domain.com/EN/home/

My htaccess file is below:
RewriteEngine on
RewriteBase /

# Force the www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] 

RewriteMap  uc int:toupper
RewriteRule ^http://www.%{HTTP_HOST}/(.*)/$ http://www.%{HTTP_HOST}/${uc:$1}/ [R=301,L]

# Add a trailing slash to paths without an extension
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule ^(.*)$ $1/ [L,R=301]

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of andrew67
andrew67

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial