I have a codeigniter project inside the b1 folder in my public_html folder:
mydomain.com/b1/controller/function
I want to change it to:
mydomain.com/controller/function
in the browser bar using a 301 redirect.
My .htaccess file in my public_html has:
RewriteEngine on
RewriteRule ^b1/(.*)$ /$1 [R=301,L,NC]
RewriteRule ^(.*)$ b1/$1
EXPLANATION:
RewriteRule ^b1/(.*)$ /$1 [R=301,L,NC] # THIS IS TO REWRITE ALL REQUESTS FROM THE NAVBAR IN MY PROJECT WHICH HAVE THE FORM mydomain.com/b1/controller/function TO mydomain.com/controller/function. AFTER THIS THE NAVBAR SHOULD SHOW mydomain.com/controller/function ( I ASSUME )
RewriteRule ^(.*)$ b1/$1 # THIS IS TO TAKE ALL INCOMING REQUESTS AND ADD A b1 IN FRONT SO mydomain.com/controller/function IS REDIRECTED TO mydomain.com/b1/controller/function - BUT INTERNALLY, SO THAT THE BROWSERS ADDRESS BAR STILL SHOWS A 'PRETTIER' mydomain.com/controller/function
According to http://htaccess.madewithlove.be/, this should work, but I still see:
mydomain.com/b1/controller/function
in my address bar.
Please note that this is a codeigniter project and CI has the following .htaccess file . ( again the project is in my public_html/b1 directory )
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
As far as I can tell mod_rewrite is working because RewriteRule ^(.*)$ b1/$1 works when a match to the rule above it does not occur.
Could some combination of the 2 .htaccess files be causing the lack of visible rerwrite in the address bar? I would like to debug this and figure out how to achieve the URL format discussed above.
Thank you,
Bill
addendum: thanks to everybody for their attempts. what I notice about multiple answers though is that:
RewriteRule ^b1/(.*)$ /$1 [R=301,L,NC]
RewriteRule ^(.*)$ b1/$1 [L]
Their seem to be a lot of L flags . In pseudocode what I want to achieve is:
IF REQUEST is mydomain.com or www.mydomain.com ( with nothing after the /) rewrite to mydomain.com . FIRST REWRITE TO REMOVE B1 IF EXISTS ( this is for the navbar requests which have form: mydomain.com/b1/controller/function which should be rewritten to mydomain.com/controller/function ) so that the address bar shows mydomain.com/controller/function
if theres an L above , I don't think it will work
Then add b1 back in internally so you redirect to b1 folder where project is stored
See Question&Answers more detail:os