删除 www 和重定向 index.html 的一些问题

发布于 2024-09-28 03:56:30 字数 860 浏览 2 评论 0原文

我在使用以下设置执行我想做的事情时遇到困难。

我想删除所有 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>      

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>      

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

没有心的人 2024-10-05 03:56:30

尝试这些规则:

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

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

Try these rules:

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

RewriteRule ^/(.*/)?index\.html$ /$1 [R=301,L]
终止放荡 2024-10-05 03:56:30

这为我解决了。正如我怀疑的那样,应用重写规则的地方存在很大的差异。包括我在内的很多人似乎都没有意识到这一点。

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

Apache HTTPD 服务器处理以下请求:离散阶段。虽然这通常对用户和管理员是透明的,但当规则集放置在不同的上下文中时,它确实会对 mod_rewrite 的行为产生影响。简单地说,当规则放置在 VirtualHost 块(或主服务器上下文中)时,它们会在服务器将请求的 URI 映射到文件系统路径之前进行评估。相反,当规则放置在 .htaccess 文件中或主服务器配置中的目录块中时,将在此阶段发生后对它们进行评估。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文