Hide folder from root URL of website
Solution 1
What you want to look into is mod_rewrite for Apache (often part of the default install).
You will then rewrite your URLs. For example:
#rewrite http://www.mysite.com/index.php to http://www.mysite.com/cms/index.php
#add more rules or RewriteCond to account for old URLs you want to keep active.
RewriteRule ^/(.*) /cms/$1
You'll probably also want to do a search on drupal and pretty or clean urls which will give you more info on this and will also let you drop the index.php.
Solution 2
Try to enable mod_rewrite and to add a rewrite rule like this:
RewriteRule ^/?(.*)$ /cms/$1
Not sure about redirects, probably you should utilize mod_proxy to handle proper redirects.
Related videos on Youtube
Sam
Updated on September 17, 2022Comments
-
Sam over 1 year
I have a website set up on shared hosting like so...
http://www.mysite.com/cms/index.php
I'd like to have the /cms folder hidden from the URL. I also need to manage redirects from the old folder structure - if that is necessary.
Thanks
Update
I ended up using this:
RewriteRule (.*) cms/$1 [L]
from this docAdded to settings.php for drupal
$base_url = 'http://www.mysite.com; // NO trailing slash!
Now just need to fix the redirects - the original pages come up, but retain the rewritten folder.
-
Admin about 13 yearsNot an apache guru here but check into .htaccess files. I think those or simple permissions will achieve what you're after.
-
-
Sam about 13 yearsmod_rewrite can't handle this with something like this? RewriteRule ^cms/(.*)$ mysite.com/$1 [R=301,L]
-
matthew about 13 years@Sam careful doing that, you could end up in a redirect loop.
-
Alex about 13 years@Sam You should try to put
RewriteRule ^cms/(.*)$ mysite.com/$1 [R=301,L]
beforeRewriteRule (.*) cms/$1 [L]
, it looks like it will work this way -
Sam about 13 yearsthat doesn't seem to be working - just leaves the url as is. I'm using WAMP(local dev server) with localhost as the domain name.