apache .htaccess子域名重定向+ wordpress

9bfwbjaz  于 2023-02-13  发布在  Apache
关注(0)|答案(3)|浏览(178)

如何启用此功能:
如果我输入:maggew.com/abcxyz
你将被重定向到mr.maggew.com/abcxyz
如果我键入:maggew.com/privacy
你将被重定向到mr.maggew.com/privacy
如果我键入:maggew.com/refund
你将被重定向到mr.maggew.com/refund
如果我输入:maggew.com/contact
你将被重定向到mr.maggew.com/contact
等等......等等......

  • 我在1&1上使用共享主机,现在我有了一个数字海洋水滴。

我尝试使用HTACCESS REDIRECT GENERATOR,但运气不佳。*

以下是我当前的.htaccess:

# 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]
oiopk7p5

oiopk7p51#

    • 备选案文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示例,你可以使用类似这样的东西来更新到新的。我不确定这有多有效。
http://www.wpbeginner.com/plugins/how-to-update-urls-when-moving-your-wordpress-site/

    • 备选案文3**

或者您可以使用http://wp-cli.org/修改数据库示例,或者您可以使用mysql命令行搜索和替换。
所有你的网址从内容和页面引用网址是存储在数据库中.你可以做一个大规模的搜索和替换如果你知道你在做什么.

ymzxtsji

ymzxtsji2#

假设您在相同的主机和目录结构上,您可以在HTTP_HOST中添加一个条件来检查子域,如果子域丢失,您可以重定向到它。

# 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]

备选

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

moiiocjp3#

下面的说明在2023年不起作用,所以我做研究。
对我来说,你可以用...

RewriteEngine On
RewriteCond %{HTTP_HOST} ^old-domain.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.old-domain.com [NC]
RewriteRule ^(.*)$  https://new-domain.com/$1  [L,R=301,NC]

详情请访问https://www.arnlweb.com/forums/web-development/what-is-htaccess-redirection-how-to-use-it

相关问题