Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am having trouble doing what i want to do with the following setup.

I would like to remove all WWW, and also forward index.html to root dir. I would like this to be for all domains, so i am doing inside httpd.conf directory directive.

I tried many variations with no success. Latest version is below (domains are inside /var/www/html, in seperate directories). > >



<Directory "/var/www/html/*/"> 
    RewriteEngine on 
    RewriteBase /  

    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]  
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]   

    #RewriteCond %{REQUEST_URI} /^index\.html/        
    RewriteRule ^(.*)index\.html$ / [R=301,L] 

        Options ExecCGI Includes FollowSymLinks 
        AllowOverride AuthConfig 
        AllowOverride All                       
        Order allow,deny 
        Allow from all 

share|improve this question
have you tried RewriteRule ^index\.html$ / [R=301,L] no need for RewriteCond, Your first rule is ok since it will take care of removing the www and redirecting the domain so when it redirects it will hit rule number 2 – Prix Oct 17 '10 at 16:01
Hello Prix. Yes I did try that. That one is wrong to start with, because it will not redirect my 2nd example above. It will redirect all index.htmls. But anyway, even that rule is not working inside directory entry properly... making it: – user54006 Oct 17 '10 at 22:58
Oh hehe my bad i didnt noticed that you were trying to use it on Directory, that's right it does take internal path into consideration etc. – Prix Oct 18 '10 at 4:36

I have not tried this, but I would approach the www redirect by creating two vhosts. One for www and one for non-www, with the only directive in the www one to redirect to the other

<VirtualHost *:80>
    Redirect /

<VirtualHost *:80>
    DocumentRoot /path/to/docroot
    ... other stuff as needed ...

If your index.html actually has your content in it, you need a DirectoryIndex that specifies index.html is a valid index in your httpd.conf:

DirectoryIndex index.html

This is typically the default, so perhaps more information is needed on what you want to accomplish with that.

share|improve this answer
Hi Alex, what i wanted to accomplish is clearly explained above. I need to get mod_rewrite working in directory level. www > non-www working fine above. index.html is not. I have DirectoryIndex also. – user54006 Oct 17 '10 at 14:51
aaah...I missed the key "for all domains" line there :) – Alex Oct 17 '10 at 15:11
Apparently, there are a lot of mistakes with my usage. For example, L meaning LAST stops processing. So 2nd rule is not seen. – user54006 Oct 17 '10 at 15:59

This solves it for me. As I suspected, there is a whole lotta difference where rewriterule is applied. Many people including me seems to be unaware of this.

The Apache HTTPD Server deals with requests in discrete phases. While this is usually transparent to the user and administrator it does have an effect on the behaviour of mod_rewrite when rulesets are placed in different contexts. To oversimplify a little, when rules are placed in VirtualHost blocks (or in the main server context) they get evaluated before the server has yet mapped the requested URI to a filesystem path. Conversely, when rules are placed in .htaccess files, or in Directory blocks in the main server config, they are evaluated after this phase has occured.

share|improve this answer

Your Answer


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