Hide folder from root URL of website

5,294

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.

Share:
5,294

Related videos on Youtube

Sam
Author by

Sam

Updated on September 17, 2022

Comments

  • Sam
    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 doc

    Added 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
      Admin about 13 years
      Not an apache guru here but check into .htaccess files. I think those or simple permissions will achieve what you're after.
  • Sam
    Sam about 13 years
    mod_rewrite can't handle this with something like this? RewriteRule ^cms/(.*)$ mysite.com/$1 [R=301,L]
  • matthew
    matthew about 13 years
    @Sam careful doing that, you could end up in a redirect loop.
  • Alex
    Alex about 13 years
    @Sam You should try to put RewriteRule ^cms/(.*)$ mysite.com/$1 [R=301,L] before RewriteRule (.*) cms/$1 [L], it looks like it will work this way
  • Sam
    Sam about 13 years
    that 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.