views:

49

answers:

3

I have a site built on codeigniter but I have come accross a small issue. Basically the homepage can be accessed through 3 different urls, being:

www.domain.com/en

www.domain.com/en/

www.domain.com/en/home.html

I'd like the first and third url to redirect to the second (www.domain.com/en/).

I've been playing around with .htaccess for hours and I can't seem to get any changes done.

Any help would be really appreciated.

Edit: Here is my current .htaccess

Options +FollowSymLinks
RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond $1 !^(index\.php|images|css|js|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [QSA,L]

RewriteCond %{HTTP_HOST} ^mywebsite.com [NC] 
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [L,R=301]

RewriteRule ^en(/home.html)?$ /en/ [L]
+1  A: 

RewriteRule ^en(/home.html)?$ /en/ [L]

This matches only /en and /en/home.html, no other urls.

Litso
This makes sense and should work but for some reason it doesn't. Whatever I try to do it seems like it has no effect. I am starting to worry that something might be conflicting in such a way that rewrites are no longer effective. I've attached my current .htaccess
Luke Vella
@user447119: Make sure to use a proper order: In general, put rules that cause an external redirect in front of those rules that just cause an internal rewrite.
Gumbo
To cause an external redirect instead of an internal rewrite, you need to set the *R* flag.
Gumbo
Thank you Gumbo you are right, I just needed to add the R flag! Thanks all for the help!
Luke Vella
+1  A: 

Your current solution doesnt work because any input has allready been captured by RewriteRule ^(.*)$ /index.php/$1 [QSA,L] The L flag denotes last, meaning that no further rules should be processed.

Options +FollowSymLinks
RewriteEngine on
RewriteBase /

#Everything from here has to do with the line mentioned above
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond $1 !^(index\.php|images|css|js|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [QSA,L] # This catches all input

RewriteCond %{HTTP_HOST} ^mywebsite.com [NC] 
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [L,R=301]

RewriteRule ^en(/home.html)?$ /en/ [L]

Instead, anything you want processed needs to be moved up before that line:

Options +FollowSymLinks
RewriteEngine on
RewriteBase /


RewriteCond %{HTTP_HOST} ^mywebsite.com [NC] 
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [L,R=301]

RewriteRule ^en(/home.html)?$ /en/ [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond $1 !^(index\.php|images|css|js|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [QSA,L]

Beyond that, reading up on mod_rewrite and regular expressions cant hurt here.

Kristoffer S Hansen
Changing the order of the rules didn't work I'm afraid. I've tried a variety of different possible solutions but I still can't get it to work. The other rewrite rules work fine, it's only this rule that isn't working.
Luke Vella
A: 

Could be as simple as changing

^en(/home.html)?$ /en/ [L]

to

^/en(/home.html)?$ /en/ [L] (notice the extra slash)

Kristoffer S Hansen