views:

139

answers:

2

I'm just trying to figure out if I'm on the right path - additional details on rewriting the URL in my example would be appreciated.

I have installed a CMS program and would simply like that www.example.com be pointed to www.example.com/cms. I just want to know if URL rewriting through apache is the best way to accomplish this?

Thank you.

+1  A: 

That's definitely the approach I would take. I'm going to assume you're using Apache, though this can easily be done with IIS as well. You'll need to edit your .htaccess file in the root directory to do this using mod_rewrite.

<IfModule mod_rewrite.c>

   RewriteEngine on

   RewriteRule    ^(.*)$ /cms/$1  [L]

</IfModule>

This should work for what you're after. Change "cms" to whatever directory you want to rewrite to.

S Pangborn
+3  A: 

Just redirecting http://example.com/ to http://example.com/cms/:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewritRule ^/?$ /cms/
</IfModule>

Redirecting all urls which otherwise would've 404d to start with /cms/:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ /cms/$1 [L]
</IfModule>

Redirecting all urls to /cms/:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^(.*)$ /cms/$1 [L]
  <Directory /var/www/html/cms/> #change this to the correct path
    RewriteEngine Off
  </Directory>
</IfModule>
elzapp