简体   繁体   English

使用.htaccess重定向将多个旧页面和非www重定向到www

[英]Redirect using .htaccess to redirect multiple old pages and non-www to www

I have the following rewrite on my .htaccess file. 我的.htaccess文件有以下重写。 It works fine but I can't redirect non-www to www. 它工作正常,但我不能将非www重定向到www。 This website also serves as a multi site wordpress installation using sub-domains. 该网站还用作使用子域的多站点wordpress安装。 So I'm pretty confused on how to have the main site redirect non-www to www links and the page redirections and not mess up the sub domain sites. 因此,我对如何让主站点将非www重定向到www链接和页面重定向以及不弄乱子域站点感到非常困惑。

<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteCond %{HTTP_HOST} ^abc\.com\.au
#RewriteRule ^(.*)$ http://www.abc.com.au/$1 [R=301,L] 

RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]

##### PAGE REDIRECTS ######
RewriteRule ^about\_abc\.htm$ "http://www.abc.com.au/company-profile/" [R=301,L]
RewriteRule . index.php [L]
</IfModule>

You must take several steps: 您必须采取以下步骤:

  1. Edit the home_url and site_url options for the main sites (in wp_options if your table_prefix is "wp_", as you want to change the urls of your main site). 编辑主站点的home_url和site_url选项(如果table_prefix为“ wp_”,则在wp_options中,因为要更改主站点的URL)。
  2. Edit the domain of your main blog in wp_blogs to www.your-domain version 将wp_blogs中主博客的域编辑为www.your-domain版本
  3. Edit wp-config DOMAIN CURRENT SITE like this: 像这样编辑wp-config DOMAIN CURRENT SITE:

     define('DOMAIN_CURRENT_SITE', 'www.example.com'); //your new www one! 
  4. Go to wp-admin of your blog and reset permalinks 转到博客的wp-admin并重置永久链接

  5. Your RewriteRule is fine, but you can make it more dynamic to use in other sites like this: 您的RewriteRule很好,但是您可以使其更动态地用于其他站点,如下所示:

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

Or, if your host multi-domains into the same network, like this: 或者,如果您的主机将多个域合并到同一网络中,则如下所示:

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

If you set up previously other blogs in your subdomain, you are safe to go, since they are linked to the previous main domain without www. 如果您以前在子域中设置了其他博客,那么就可以放心了,因为它们链接到了以前的主域而没有www。 I've tested personally this recipe into a multi-domains network migrated to www main domains last month. 上个月,我已经对该配方进行了个人测试,并将其迁移到了一个多域网络,该网络已迁移到www主要域。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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