简体   繁体   中英

Wordpress Multisite Domain Redirects

I have a Wordpress multisite with a primary domain that is used for admin site management and then hundreds of other sites that each have their own unique domain (NOT a subfolder or subdomain of the primary site).

I need to redirect each site to its corresponding landing page on our main site. I am programmatically generating these redirect rules since there are hundreds of redirects that need to be set up. I am then adding those redirect rules to one master .htaccess file at the document root.

Here is what I have so far:

RewriteCond %{HTTP_HOST} ^(.*)?firstsite.com [NC]
Redirect 301 / https://newsite.com/1234/ 

RewriteCond %{HTTP_HOST} ^(.*)?secondsite.com [NC]
Redirect 301 / https://newsite.com/5678/

What I'm seeing is that it is redirecting all traffic from any of the sites to the first "Redirect 301" address ( https://newsite.com/1234/ ). Presumably because I'm doing "Redirect 301 /" which is redirecting the document root of the entire Wordpress multisite instead of the root of the "RewriteCond" domain specified.

How do I set up essentially a conditional redirect based on the domain being accessed?

I should mention that I do not have Nginx installed on the server.

RewriteCond and RewriteRule work together. So the Redirect 301 was running independently of the RewriteCond. This will work:

RewriteCond %{HTTP_HOST} ^(.*)?firstsite.com [NC]
RewriteRule ^(.*)$ https://newsite.com/1234/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^(.*)?secondsite.com [NC]
RewriteRule ^(.*)$ https://newsite.com/5678/$1 [R=301,L]

Also, be sure to place this at the very top of your .htaccess rewrite rules. Right underneath the line that says:

RewriteEngine On

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