2010-10-17 91 views
0

我在做下面的设置时想做什么时遇到问题。删除www和重定向index.html的一些问题.html

我想删除所有WWW,并将index.html转发到根目录。我希望这是为所有域,所以我在做httpd.conf目录指令。

我尝试了许多变化没有成功。最新版本如下(域位于/ var/www/html中,位于单独的目录中)。

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

感谢,

玛丽亚

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

回答

0

尝试下列规则:

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

RewriteRule ^/(.*/)?index\.html$ /$1 [R=301,L] 
+0

我得到:http://example.com//var/www/html/example当我要求http://www.example.com/index.html时 – MariaKeys 2010-10-17 16:09:53

0

这解决了对我来说。正如我所怀疑的那样,在应用rewriterule的情况下存在很大差异。包括我在内的许多人似乎都不知道这一点。

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

在独立的阶段请求执行Apache服务器的交易。虽然这对用户和管理员来说通常是透明的,但当规则集放置在不同的上下文中时,它对mod_rewrite的行为有影响。简单一点,当规则放置在VirtualHost块(或主服务器上下文中)时,它们在服务器尚未将请求的URI映射到文件系统路径之前进行评估。相反,当规则放置在.htaccess文件或主服务器配置中的目录块中时,它们将在此阶段发生后进行评估。