I am attempting to map specific subdomains on my WordPress Multisite.
I have successfully mapped my multisite subdomains to their new domains.
Example:
I need to make it so that anyone who knew about store5.domain.com will be redirected to prodomain.com
I have several instances of this, where I will need to replicate this code often as I perform these changes, so any assistance in understanding how I am using this code would be very helpful for me.
What can I do to safely adjust my .htaccess file so I can 301 redirect people from the specific domain(s)?
Example: The now out of use: storeX.domain.com 301 permanent redirects to the live prodomain.com
I cannot accomplish this in a simple fashion because I am using SiteGround, I am using a wildcard subdomain and wildcard SSL on the core domain to safely auto-secure the SSL certificates for any newly added subsites.
Because of the wildcard SSL, and because there is a Wildcard Subdomain, I am unable to create a core redirect for Store5.domain.com from within the control panel like normal, and because they are subdomains rather than sub-directories (sub.domain.com / not domain.com/sub) I cannot use a simple fix like a redirection plugin.
The only option I understand that will work will be redirection using .htaccess.
My current htaccess looks like this (I have zero skill in writing htaccess):
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
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]
RewriteRule . index.php [L]
AddHandler application/x-httpd-php74 .php .php5 .php4 .php3
How I rewrote the core on .htaccess.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^store5\.domain\.com [NC]
RewriteRule $ https://newdomain.com/$1 [L,R]
Here is how my example now looks:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^store5\.domain\.com [NC]
RewriteRule $ https://domain1.com/$1 [L,R]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^store2\.domain\.com [NC]
RewriteRule $ https://domain2.com/$1 [L,R]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
AddHandler application/x-httpd-php74 .php .php5 .php4 .php3
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.