Forum Moderators: phranque

Message Too Old, No Replies

remove directory from url with .htaccess

         

cinemaduro

3:50 pm on May 17, 2010 (gmt 0)

10+ Year Member



I just developed a new site for a client. It's all in a folder called /cms/. Is there a way to use mod rewrite to get rid of the cms folder in the URL? And at the same time make sure anyone going to the top-level of the domain (mydomain.com) sees the home page located at mydomain.com/cms/?

Also, I just want the /cms/ directory to be hidden. There are other directories like mydomain.com/pma/ that I still need to be able to access.

I've tried several suggestions, even some found on these forums, but nothing seems to be working. I admittedly, don't really understand .htaccess syntax yet, so I'm shooting in the dark as they say.

I've pieced together this chunk of code, which partially works (seems to display content from mydomain.com/cms/index.php, when someone goes to mydomain.com, but doesn't re-write anything if someone goes to mydomain.com/cms/index.php, or mydomain.com/cms/some-other-page.php (like when they click on a dynamic site link):


Options +FollowSymlinks
RewriteEngine On
RewriteBase /

## hide index from home
RewriteRule ^cms/index\.(htm|html|php) http://mydomain.com/ [R=301,L]

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

## rewrite home page to not use /cms/
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$
RewriteCond %{REQUEST_URI} !^/cms/
RewriteCond %{HTTP_HOST} !^/pma/
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$
RewriteRule ^(/)?$ cms/index.php [L]


I'd also like to try and cut down on duplicate content by removing the index pages so I don't have /cms/ and /cms/index.php being different links.

any help would be greatly appreciated.

-Tristan

g1smd

4:17 pm on May 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The index.php problem is very simple to solve and the code has been posted hundreds of times before.

The /cms/ problem is more tricky. How is .htaccess to know whether new URL request /some-topic is to be served from the /cms/ folder or from elsewhere? The easiest way for it to know that content comes from the cms, is to specify that in the URL in some way. The easiest is to use a unique 'prefix' such as /cms/ or c-, or whatever you choose.

cinemaduro

8:39 pm on May 17, 2010 (gmt 0)

10+ Year Member



>>The easiest is to use a unique 'prefix' such as /cms/ or c-, or whatever you choose.

Ok, so are you saying that the way it's currently set up is the most practical and best way to do it (without physically moving files)?

g1smd

9:18 pm on May 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes, it is the simplest way and it is also the one most likely to preserve your sanity. :)