views:

225

answers:

2

I want to redirect all queries to mydomain.com to mydomain.com/live/. I'm already able to do that, however I have trouble with the URL displayed in the browser. I have two goals, (1) that the URL always renders with "www" in front and (2) that the sub folder "live" is not displayed in the url.

EDIT: Based on edited code by Cryo the following accomplishes my goals and also adds a trailing slash after all subfolders so that when a folder is typed in the url it's correctly forwarded to the index.html inside of it:

RewriteCond %{HTTP_HOST} !^www\.domain\.com$
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
RewriteRule ^$ /index.html

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\..+$
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.domain.com/$1/ [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/live/
RewriteRule ^(.*)$ /live/$1

Question though, when adding a trailing slash to subfolders, I assumed RewriteCond %{REQUEST_FILENAME} !-f would make it so that a slash isn't added after file names (only folders) so /subfolder/page.html would not have a trailing slash (which is what I want). However RewriteCond %{REQUEST_FILENAME} !-f seems to do nothing and RewriteCond %{REQUEST_URI} !..+$ is needed.

A: 

If you want to avoid putting 'live' in the URL it sounds like what you want is not a redirect but a reverse proxy.

Jherico
A: 
RewriteCond %{HTTP_HOST} !^www\.georgemitra\.com$
RewriteRule ^(.*)$ http://www.georgemitra.com/$1 [R=301,L]

RewriteRule ^$ /index.html
RewriteRule ^blog$ /blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/live/
RewriteRule ^(.*)$ /live/$1

You almost had it. I moved the www subdomain catch-all to go first and push it to the browser before continuing. Then when the request comes back I just added the index.html force on the root and the catch for /blog without a trailing slash. Hope that helps.

Cryo
Thanks! Almost perfect, the only thing is that I'd like to add a trailing slash to every subfolder not just "blog". I edited my post above with your changes plus another change of mine to get this functionality. It works now, however I'm using the conditions RewriteCond %{REQUEST_FILENAME} !-f and RewriteCond %{REQUEST_URI} !(.*)/$ to prevent adding a trailing slash to URLs that point directly to a file name like /subfolder/page.html. I'm confused because I would think that I would only need the first rule to accomplish this, but the first rule alone doesn't do anything.
George