简体   繁体   中英

Force Redirect www.domain.com\blog to domain.com\blog .htaccess?

I have a wordpress Multisite instance that for some reason defaults to domain.com (/blog with no www in front. Any request with a www in front gets forced to the home page (domain.com/blog) and not to it's intended page of say domain.com/blog/page.

What I am trying to do is force all incoming traffic to strip off www if it exists and just go to /blog/what-ever-page-youre-trying-to-go-to. I need it to go to the page that is requested, currently if you have anything on the end of the /blog URL (/blog/ANY-PAGE-HERE) it defaults to /blog.

Anyone have any idea how I would go about fixing this? In .htaccess seems to be the easiest way but I can't seem to find a viable solution after working on it for a couple of hours.

PS: it's multisite so I cannot just go into setting and change the URL and HOME to www.domain/blog

This is what I use on my sites:

<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>

Add this above all your wordpress stuff in the htaccess of your document root:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM