Apache 使用虚拟主机将不存在的页面重定向到主页,将example.org重定向到www.example.org in.htaccess
我正在Ubuntu apache2上测试一些东西。我能够解决个别问题,但当这些问题结合起来时,它会变得一团糟,并显示“此网页有一个重定向循环”。好的。这是设置。 我的网站是www.example.org和子文件夹www.example.org/kmc。在子文件夹中,我们安装了Joomla CMS 在.htaccess文件中,我做了两个设置 1) example.org将转发至www.example.orgApache 使用虚拟主机将不存在的页面重定向到主页,将example.org重定向到www.example.org in.htaccess,apache,.htaccess,mod-rewrite,redirect,apache2,Apache,.htaccess,Mod Rewrite,Redirect,Apache2,我正在Ubuntu apache2上测试一些东西。我能够解决个别问题,但当这些问题结合起来时,它会变得一团糟,并显示“此网页有一个重定向循环”。好的。这是设置。 我的网站是www.example.org和子文件夹www.example.org/kmc。在子文件夹中,我们安装了Joomla CMS 在.htaccess文件中,我做了两个设置 1) example.org将转发至www.example.org RewriteEngine On RewriteCond %{HTTP_HOST} !^w
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>
DocumentRoot/var/www/html/kmc
服务器名www.example.org
现在,当我转到example.org时,浏览器显示“此网页有一个重定向循环”。您
www
规则应该是这样的:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
您的规则在目标URL中缺少
www.
。是否在http://www.example.org
?是的。只需简单的index.html