views:

32

answers:

3

Dear All,

I am a newbie to ubuntu and apache. Can someone tell me how I could direct to

www.mysite.com/drupal6

when user address www.mysite.com?

Thanks a lot.

Cheers.

+1  A: 

Look at Apache's mod_rewrite documentation. You will need a RewriteRule in your apache configuration at the minimum, you may also need RewriteCond's to define when the RewriteRule is used.

Your rewrite pattern will be rewriting the REQUEST_URI with something from: ^/$ to: /drupal6. The ^ and $ are essential to prevent Apache getting into an infinite loop while rewriting the base URI by only matching "/" and not "/anything-else".

I assume you're on a recent version of Ubuntu and Apache? If so, see the Apache 2.2 documentation on mod_rewrite.

Andy Shellam
+2  A: 

This should work. Create a file in the root folder of your server called .htaccess - the dot at the beginning is very important as this helps the server identify the file as a hidden / system config file.

Open the file and paste the following lines of code in :

Options +FollowSymlinks
RewriteEngine on

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ www.mysite.com/drupal6/$1 [R,L]

This should force all traffic to the server to redirect to your custom folder.

A brief explanation of the .htaccess code

If you want rewrites to work, you have to enable the Rewrite Engine and tell the server to follow symlinks.

The second section establishes the rule - specifically applying it to all traffic on the standard web port of 80.

The final line tells the server to grab everything after the URL and append it to the new address (mysite.com/drupal6).

There's a lot more you can do with .htaccess files but you really need to Google for good examples to test out.

Robin Layfield
+2  A: 

If you are running Apache and Ubuntu, there is actually a really easy way to force this redirect using a simple php script.

Create an index.php file in the root of your server and paste the following code into it

<?php header("location: drupal6/") ?>

This will cause the site to auto-redirect to the drupal6 folder whenever it is visited.

Robin Layfield