[英]Redirect www.domain.com/112 to www.domain.com/ using htaccess 301 redirect
[英]301 redirect from www.domain.com/index.html to www.domain.com not working
在apache配置文件(即httpd.conf)中,我们进行了虚拟主机配置,该配置已使用了两年。 今天到那里没有问题。 但是,当我被要求向其添加重定向时,它不起作用。 我的virtualHost容器看起来像这样
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName domain.com
Redirect 301 / http://www.domain.com/
Redirect 301 /index.html http://www.domain.com/
</VirtualHost>
在这里,当我键入“ http://domain.com”时,它会进入“ http://www.domain.com”的预期行为。 但是,当我键入“ http://domain.com/index.html”或“ http://www.domain.com/index.html”时,并没有带我进入“ http://www.domain.com” ...这是joomla网站。
谁能为我解决这个问题...
提前致谢
加
ServerAlias www.domain.com
在ServerName domain.com
之后的新行中
听起来好像是在尝试第二个重定向之前先应用了第一个重定向。 您是否尝试过以其他顺序放置重定向行?
Redirect 301 /index.html http://www.domain.com/
Redirect 301 / http://www.domain.com/
通常,这是通过对mod_rewrite使用更通用的方法来实现的:
此代码应放在域根目录的htaccess文件中,即domain.com/.htaccess或virtualhost配置。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
</IfModule>
(例如,这里也用PHP / htaccess / mod_rewrite强制www前缀 )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.