【问题标题】:redirecting non existed page to home page and example.org to www.example.org in .htaccess with virtual hosting使用虚拟主机将不存在的页面重定向到主页并将 example.org 重定向到 .htaccess 中的 www.example.org
【发布时间】:2015-02-23 21:34:08
【问题描述】:

我正在 Ubuntu apache2 上测试一些东西。我能够解决个别问题,但是当这些问题结合起来时,它会变得混乱并显示“这个网页有一个重定向循环”。好的..这是设置。 我的网站是 www.example.org 和子文件夹 www.example.org/kmc。在子文件夹中,我们安装了 Joomla CMS。

在 .htaccess 文件中,我做了两个设置。

1) example.org 将被转发到 www.example.org

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

有效。

2) 不存在的页面会被转发到首页。

ErrorDocument 404 http://www.example.org

它也有效。

现在我在 000-default.conf 文件中设置虚拟主机。原因是我想在同一台服务器上安装两个不同的站点。

<VirtualHost *:80>
    DocumentRoot /var/www/html/kmc
    ServerName www.example.org
</VirtualHost>

现在,当我访问 example.org 时,浏览器显示“此网页具有重定向循环”。

【问题讨论】:

  • http://www.example.org有页面吗?
  • 是的。只是简单的 index.html

标签: apache .htaccess mod-rewrite redirect apache2


【解决方案1】:

www的规则应该是这样的:

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

您的规则在目标 URL 中缺少 www.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-18
    • 2014-02-17
    • 2011-05-24
    • 2022-06-30
    • 2021-06-13
    • 2014-01-07
    • 2012-04-23
    • 2023-03-27
    相关资源
    最近更新 更多