tags:

views:

23

answers:

1

I have the htaccess rules below that work almost perfectly. When I load

http://localhost:8888/site/name/register/ it redirects to http://localhost:8888/site/name/fr/register/ as is intended.

But when I load http://localhost:8888/site/name/register (sans trailing slash) the redirect does not occur. I'm sure I just need to add a slash somewhere in the .htaccess rules but can not find where (adding it to the RewriteBase makes no difference).

       RewriteEngine On
RewriteBase /site/name/

#some URI processing also occurs in routing.php!
RewriteCond $1 !^(fr|nl)$

#don't apply the rule to the assets folders
RewriteCond $1 !^css$
RewriteCond $1 !^js$

RewriteRule ^([^/]+)/.* /site/name/fr/$0 [L,R=301]    

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

Note the site homepage is http://localhost:8888/site/name

How can I get the redirect to occur also at http://localhost:8888/site/name/register ?

+1  A: 

^([^/]+)/.* means everything that comes before the first slash. In other words, a slash is required. If you just remove the slash it should work.

 RewriteRule ^([^/]+).* /site/name/fr/$0 [L,R=301]
Alxandr
Hmm no I'm getting "page not redirecting properly" for url's with and without slash.
stef
What do you mean? Like an exception?
Alxandr