简体   繁体   English

使用通配符 SSL 重定向特定子域 .HTACCESS 用于 WordPress 多站点且无内部重定向

[英]Redirect Specific Sub-domains .HTACCESS For WordPress Multisite With Wildcard SSL And No Internal Redirects

I am attempting to map specific subdomains on my WordPress Multisite.我正在尝试在我的 WordPress 多站点上的 map 特定子域。

I have successfully mapped my multisite subdomains to their new domains.我已成功地将我的多站点子域映射到他们的新域。

Example:例子:

Store5.domain.com is now successfully changed to prodomain.com and everything works fine, up and to one point. Store5.domain.com 现在已成功更改为 prodomain.com 并且一切正常,最多一点。

I need to make it so that anyone who knew about store5.domain.com will be redirected to prodomain.com我需要这样做,以便任何了解 store5.domain.com 的人都将被重定向到 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)?我可以做些什么来安全地调整我的 .htaccess 文件,以便我可以 301 重定向来自特定域的人?

Example: The now out of use: storeX.domain.com 301 permanent redirects to the live prodomain.com示例:现在不再使用:storeX.domain.com 301 永久重定向到实时 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.我无法以简单的方式完成此操作,因为我使用的是 SiteGround,我在核心域上使用通配符子域和通配符 SSL 以安全地自动保护任何新添加的子站点的 SSL 证书。

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.由于通配符 SSL 和通配符子域,我无法像正常一样从控制面板中为 Store5.domain.com 创建核心重定向,并且因为它们是子域而不是子目录(sub.domain .com / not domain.com/sub)我不能使用像重定向插件这样的简单修复。

The only option I understand that will work will be redirection using .htaccess.我知道唯一可行的选择是使用 .htaccess 进行重定向。

  • Additional Goal: Ideally, I would like to include a way to make it so that if someone visits store5.domain.com/product/name will get redirected like a wildcard redirect, where it doesn't matter what they put after the slash, the first part will change from store5.domain.com to prodomain.com and the end of it will remain unchanged.*附加目标:理想情况下,我想包括一种方法,以便如果有人访问 store5.domain.com/product/name 将像通配符重定向一样被重定向,在斜杠后面放什么并不重要,第一部分将从 store5.domain.com 更改为 prodomain.com 并且它的结尾将保持不变。*

My current htaccess looks like this (I have zero skill in writing htaccess):我当前的 htaccess 看起来像这样(我在编写 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.我如何重写 .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

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

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