如何重定向所有的WWW流量与htaccess的等于非www网页 [英] how to redirect all www traffic with htaccess to equal non-www pages

查看:150
本文介绍了如何重定向所有的WWW流量与htaccess的等于非www网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是pretty的简单我想,但我不这样做我自己。

Question is pretty simple I guess, but I fail to do this myself.

我在 http://website.com 一个网站,并希望301重定向www.website所有请求。 com可以 http://website.com/ 但要确保所有的目录和文件名保持不变(所以不是所有的请求结束了在主页)。

I have a website on http://website.com and want to 301 redirect ALL requests on www.website.com to http://website.com/ but make sure all directories and filenames stay the same (so not all requests end up at the homepage).

所以,无论人可以输入(如www.website.com/something.here)要301重定向到website.com/something.here~~V

So whatever people may type (like www.website.com/something.here) should 301 redirect to website.com/something.here

如何做到这一点?

推荐答案

下面添加到您的的.htaccess 文件。应该做的伎俩。

Add the below to your .htaccess file. Should do the trick.

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

这需要重写引擎是...

This requires that the rewrite engine is on...

<IfModule mod_rewrite.c>

############################################
## enable rewrites

    Options +FollowSymLinks
    RewriteEngine on

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

</IfModule>

这篇关于如何重定向所有的WWW流量与htaccess的等于非www网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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