Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am trying to redirect /folder to / using .htaccess but all am I getting is the Apache HTTP Server Test Page. My root directory looks like this:

/
.htaccess
-/folder
-/folder2
-/folder3

My .htaccess looks like this:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/folder/
RewriteRule (.*) /folder/$1 

What am I doing wrong? I checked my httpd.conf (I'm running Centos) and the mod_rewrite library is being loaded. As a side note, my server is not a www server, it's simply a virtual machine so it's hostname is centosvm.

Addition: My httpd.conf looks like so:

<VirtualHost *:80>
        ServerName taa.local
        DocumentRoot /var/www/html
        SetEnv APPLICATION_ENV "dev"
        Alias /taa /var/www/html/taa/public
        <Directory /var/www/html/taa/public>
                DirectoryIndex index.php
                AllowOverride All
                Order allow,deny
                Allow from all
        </Directory>
</VirtualHost>
share|improve this question

3 Answers 3

Make sure Mod_Rewrite is loaded. Make sure you have AllowOverrides All on your root directory (it's the Apache default, but most distros have a default none in the httpd.conf file).

share|improve this answer
    
I do have allow Overrides All turned on. –  manyxcxi Jun 10 '10 at 18:43
up vote 0 down vote accepted

I figured out that my <VirtualHost> declaration was missing a <Directory> declaration for root. By changing my <VirtualHost to:

<VirtualHost *:80>
        ServerName taa.local
        DocumentRoot /var/www/html
        SetEnv APPLICATION_ENV "dev"
        Alias /folder1 /var/www/html/folder1/public
        <Directory /var/www/html>
                AllowOverride All
                Order allow,deny
                Allow from all
        </Directory>
        <Directory /var/www/html/folder1/public>
                DirectoryIndex index.php
                AllowOverride All
                Order allow,deny
                Allow from all
        </Directory>
</VirtualHost>

My /.htaccess looks like:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/folder1/
RewriteCond %{REQUEST_URI} !^/folder2/
RewriteCond %{REQUEST_URI} !^/folder3/
RewriteCond %{REQUEST_URI} !^/folder4/
RewriteCond %{REQUEST_URI} !^/folder5/
RewriteRule (.*) folder1/$1 [L]

It would be cleaner if I knew hot to say if REQUEST_URI = /, then redirect but I don't know how.

share|improve this answer

You need to drop the initial '/' from a match with RewriteCond

See the examples in http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritecond

RewriteEngine On 
RewriteCond %{REQUEST_URI} !^folder/ 
RewriteRule (.*) /folder/$1
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.