Php .htaccess子域重定向+;wordpress

Php .htaccess子域重定向+;wordpress,php,wordpress,apache,.htaccess,redirect,Php,Wordpress,Apache,.htaccess,Redirect,如何启用此功能: 如果我键入:maggew.com/abcxyz 您将被重定向到mr.maggew.com/abcxyz 如果我键入:maggew.com/privacy 您将被重定向到mr.maggew.com/privacy 如果我键入:maggew.com/return 您将被重定向到mr.maggew.com/return 如果我键入:maggew.com/contact 您将被重定向到mr.maggew.com/contact 等等…等等…等等 我在1&1上使用共享主机,现在我有了一个

如何启用此功能:

如果我键入:
maggew.com/abcxyz

您将被重定向到
mr.maggew.com/abcxyz

如果我键入:
maggew.com/privacy

您将被重定向到
mr.maggew.com/privacy

如果我键入:
maggew.com/return

您将被重定向到
mr.maggew.com/return

如果我键入:
maggew.com/contact

您将被重定向到
mr.maggew.com/contact

等等…等等…等等

我在1&1上使用共享主机,现在我有了一个数字海洋水滴。
我试着用,但运气不好

这是我当前的访问权限:

# REDIRECTS STORE
redirect 301 /shop http://mr.maggew.com/store
redirect 301 /market http://mr.maggew.com/store
redirect 301 /outlet http://mr.maggew.com/store
redirect 301 /bazaar http://mr.maggew.com/store
redirect 301 /boutique http://mr.maggew.com/store

# PROTECT WP-CONFIG.PHP
<files wp-config.php>
order allow,deny
deny from all
</files>

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

#force subdomain of mr.maggew.com
RewriteCond %{HTTP_HOST} !^mr\.
RewriteRule (.*) http://mr.maggew.com%{REQUEST_URI} [R,L,QSA]
#重定向存储
重定向301/商店http://mr.maggew.com/store
重定向301/市场http://mr.maggew.com/store
重定向301/出口http://mr.maggew.com/store
重定向301/集市http://mr.maggew.com/store
重定向301/精品店http://mr.maggew.com/store
#保护WP-CONFIG.PHP
命令允许,拒绝
全盘否定
重新启动发动机
重写基/
重写规则^index\.php$-[L]
#在/wp admin中添加尾部斜杠
重写规则^([_0-9a-zA-Z-]+/)?wp admin$$1wp admin/[R=301,L]
RewriteCond%{REQUEST_FILENAME}-f[或]
RewriteCond%{REQUEST_FILENAME}-d
重写规则^-[L]
重写规则^([_0-9a-zA-Z-]+/)?(可湿性粉剂-(内容|管理|包括)。*)$2[L]
重写规则^([[u 0-9a-zA-Z-]+/)?(.\.php)$$2[L]
重写规则。index.php[L]
#mr.maggew.com的强制子域
重写cond%{HTTP_HOST}^先生\。
重写规则(.*)http://mr.maggew.com%{REQUEST_URI}[R,L,QSA]

假设您位于同一主机和目录结构上,您可以在HTTP_主机中为子域添加条件检查,如果子域丢失,您可以重定向到它

# REDIRECTS STORE
redirect 301 /shop http://mr.maggew.com/store
redirect 301 /market http://mr.maggew.com/store
redirect 301 /outlet http://mr.maggew.com/store
redirect 301 /bazaar http://mr.maggew.com/store
redirect 301 /boutique http://mr.maggew.com/store

# PROTECT WP-CONFIG.PHP
<files wp-config.php>
order allow,deny
deny from all
</files>

RewriteEngine On
#force subdomain of mr.maggew.com
RewriteCond %{HTTP_HOST} !^mr\.
RewriteRule /?(.*)$ http://mr.maggew.com/$1 [R,L,QSA]

RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

选项1

before you do all the folder specific redirects you need to redirect the domain first
RewriteEngine On
RewriteCond %{HTTP_HOST} ^http://www\.domain.com\/ [NC]
RewriteRule ^(.*)$ http://sub.domain.com/$1 [R=301,L]
选项2

如果您的内容中有旧的url实例,您可以使用类似的内容更新到新的url实例。我不确定这有多有效

选项3

或者可以使用modify数据库实例,也可以使用mysql命令行搜索和替换


来自内容和页面引用URL的所有URL都存储在数据库中。如果你知道自己在做什么,你可以进行大规模搜索和替换

试图添加一个重写条件,在其中检查输入的域?然后用301[L]重定向到你的新url我不明白你想说什么。下面的两个答案是我想说的,很抱歉,我将你的代码片段添加到了.htaccess文件的顶部,但它没有重定向。例如,如果我输入maggew.com/training,它会重定向到主页,而不是看起来正确的mr.maggew.com/training。试试这个非常简单的代码:RewriteCond%{HTTP_HOST}^maggew\.com$[NC]RewriteRule^(.*)$[R=301,L]我刚刚粘贴了您的更新代码,并使我的.htaccess文件如下所示:--另外,我在Chrome中打开了一个私有选项卡以进行双重测试检查,但仍然没有运气。我将尝试将unixmiah添加到文件中,看看是否有效。@MaggewDotCom暂时禁用所有自定义非必需插件(尤其是与缓存或安全有关的插件),检查WP管理常规设置,并确保您的站点地址和wordpress地址已更新为新的URL。@MaggewDotCom使用我提供的代码片段对我的wordpress站点进行的所有测试均使用标准wordpress配置,包括登录页、嵌套子类别和wp管理员。我确实必须将重定向移到wordpress重定向之上。我更新了答案以演示我的测试。当我将您的代码块从选项1(不包括您的“before you do all…”)复制/粘贴到.htaccess文件的顶部时,我没有任何运气。例如,当我键入maggew.com/training时,它没有重定向到mr.maggew.com/training——我现在要尝试选项2和3
before you do all the folder specific redirects you need to redirect the domain first
RewriteEngine On
RewriteCond %{HTTP_HOST} ^http://www\.domain.com\/ [NC]
RewriteRule ^(.*)$ http://sub.domain.com/$1 [R=301,L]