强制重定向www.domain.com \ blog到domain.com \ blog .htaccess?

时间:2012-07-12 19:46:29

标签: wordpress .htaccess

我有一个wordpress Multisite实例,由于某种原因默认为domain.com(/博客前面没有www。任何带有www的请求都被强制到主页(domain.com/blog)而不是它是domain.com/blog/page的目标页面。

我想要做的是强制所有传入的流量剥离www(如果存在)并且只是去/ blog / what-ever-page-youre-trying-to-go-to。我需要它转到所请求的页面,目前如果您在/ blog URL的末尾有任何内容(/ blog / ANY-PAGE-HERE),则默认为/ blog。

任何人都知道如何解决这个问题?在.htaccess中似乎是最简单的方法,但在工作几个小时之后我似乎找不到可行的解决方案。

PS:它是多站点,所以我不能只是设置并将URL和HOME更改为www.domain / blog

2 个答案:

答案 0 :(得分:1)

这就是我在网站上使用的内容:

<IfModule mod_rewrite.c>
  RewriteEngine on

  # If your site can be accessed both with and without the 'www.' prefix, you
  # can use one of the following settings to redirect users to your preferred
  # URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
  #
  # To redirect all users to access the site WITH the 'www.' prefix,
  # (http://example.com/... will be redirected to http://www.example.com/...)
  # adapt and uncomment the following:
  RewriteCond %{HTTP_HOST} ^domain\.net$ [NC]
  RewriteRule ^(.*)$ http://www.domain.net/$1 [L,R=301]
</IfModule>

答案 1 :(得分:0)

在文档根目录的htaccess中添加以上所有wordpress内容:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain\.net$ [NC]
RewriteRule ^blog(.*) http://domain.net/blog$1 [L,R=301]