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

   IT问题网   2018-03-09 00:00:00

问 题

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

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

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

如何做到这一点?

解决方案

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

 的rewritecond%{http_host} ^ yoursite.com
重写规则(。*)http://www.yoursite.com/$1 [r = 301,l]
 

这需要重写引擎是...

  ifmodule mod_rewrite.c

############################################
##启用重写

选项+的followsymlinks
rewriteengine叙述上

的rewritecond%{http_host} ^ yoursite.com
重写规则(。*)http://www.yoursite.com/$1 [r = 301,l]

 / ifmodule
 

标签:如何定向有的流量等于网页



分享:

  • 微信
  • QQ好友
  • QQ空间
  • 新浪微博


热门推荐

重定向移动网站子域(Redirect mobile website to subdomain)

problem i'm trying to redirect my website to a subdomain ...

我希望我的网站有"案件敏感"网址(I want my site to have "case in-sensitive" url)

problem how to make url case in-sensitive www ...

创建一个.htaccess文件?(Creating an .htaccess file)

problem how to create an .htaccess file is it required to ...

如何重定向多个类似的URL同一个查询?(How to redirect multiple similar URLs with one query)

problem i currently have lots of urls that look like this ...

设置在.htaccess display_error PHP配置(Setting display_error PHP configuration in .htaccess)

problem i'm trying to disable display_errors from .htacce ...

使用浏览器的URL prevent直接访问图像(Prevent direct access to images using the browser url)

problem i have a folder named - images. this folder conta ...

盗链保护,正确的.htaccess规则?(Hotlink protection, correct .htaccess rules)

problem i saw on many blogs and also on many answers here ...

桌面/移动htaccess的重写规则多个条件(htaccess rewriterule multiple conditions for desktop/mobile)

problem i am using a server-side image resize ...

网站将不会加载未经WWW preFIX - 字preSS?(Website Won't Load without WWW Prefix - WordPress)

problem we had this issue before with our old website, bu ...

强制www和斜线与htaccess的的mod_rewrite在多域站点(Enforce www and trailing slash with mod_rewrite htaccess on a multi-domain site)

problem my goal is to enforce www and a trailing slash on ...

如何查看重写规则或服务器的RewriteCond变量的值?(How can I see the value of RewriteRule or RewriteCond server variables)

problem for example, if i want to see what va ...

htaccess的301重定向问题URL变量(htaccess 301 redirect issue with url variables)

problem if i use this code, it's successful: redirect 30 ...

在重写规则重用子域(Reuse subdomain in a rewrite rule)

problem i'm a bit stuck with my redirect rule. little exa ...

mod_rewrite的删除斜杠不工作在Laravel(mod_rewrite remove trailing slash not working in Laravel)

problem i have the following code setup in my htaccess fi ...

重定向domain.com到domain.com/category不改变URL的地址栏(Redirect domain.com to domain.com/category without changing the url in address bar)

problem i need to redirect for prestashop 1.5.3.1: when u ...

.htaccess中使用托管现场测试(Htaccess to use the hosting for live testing)

problem i would use the hosting for live testing, but i ...

htaccess的:删除扩展名为.php(htaccess: Remove .php extension)

problem i have a file named show.php i want to remove .p ...

htaccess的重写规则 - 检查引荐,如果错了引荐发送到特定的URL,如果正确,允许目录读取(.htaccess rewriterule - check for referrer, if wrong referrer send to a specific URL, if right, allow directory to be read)

problem i have a folder on my site (domain.com/protect) i ...

最好的办法,为的.htaccess临时重定向(302)与异常(Best way to for .htaccess temporary redirect (302) with exception)

problem first, i realise there are quite a few posts on . ...

PHP的国防部重写的.htaccess忽略目录(php mod rewrite .htaccess ignore directory)

problem what rule should i set, to make the mod_rewrite i ...