views:

46

answers:

2

Hello Fellas,

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).

http://www.example.com/index.html > http://example.com
http://www.example.com/someother/index.html > http://example.com/someother/

Thanks,

Maria

<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

 </Directory>      
A: 

Try these rules:

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

RewriteRule ^/(.*/)?index\.html$ /$1 [R=301,L]
Gumbo
I am getting: http://example.com//var/www/html/example when I request http://www.example.com/index.html
MariaKeys
A: 

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.

http://wiki.apache.org/httpd/RewriteContext

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.

MariaKeys