通过Apache重写规则永久重定向 [英] Permanent redirect via apache rewrite rules

查看:117
本文介绍了通过Apache重写规则永久重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个规则,一个域名permenantly重定向到另一个域名

I am trying to write a rule to permenantly redirect a domainname to another domain name

RewriteCond %{HTTP_HOST} ^www.companyname1.com$
RewriteRule ^(.*)$ http://www.companyname2.com/$1 [R=301,L]

这只有当用户会记住WWW输入,如果用户没有在此网址www工作类型,页面将加载,但图片链接将被打破。

This only works if the user remembers to type in www, if the user does not type in www in the url, the page will load but the image links will be broken.

有谁知道如何调整上述规则,它有和没有WWW工作的?

Does anyone know how to adjust the above rule to it works with and without www?

我使用的是灯配置,阿帕奇2在RedHat。

I am using a LAMP configuration, apache 2 on redhat.

推荐答案

您可以提供几个可选的重写,条件[OR]:

You can supply several optional Rewrite-Conditions with [OR]:

RewriteCond %{HTTP_HOST} ^www.companyname1.com$ [OR]
RewriteCond %{HTTP_HOST} ^companyname1.com$
RewriteRule ^(.*)$ http://www.companyname2.com/$1 [R=301,L]

这应该做的伎俩。第一重写,条件触发,如果www是present,第二个火,如果WWW已经被遗忘了。

This should do the trick. The first Rewrite-Condition fires, if www is present, the second one fires, if www has been forgotten.

这篇关于通过Apache重写规则永久重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆