php - .htaccess 子域重定向 + wordpress

标签 php wordpress apache .htaccess redirect

如何启用它:

如果我输入: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 上使用共享主机,现在我有了一个 digital ocean 水滴。
我尝试使用 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]

最佳答案

选项 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 命令行搜索和替换。

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

关于php - .htaccess 子域重定向 + wordpress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27230299/

相关文章:

apache - htaccess 重定向 URI 到父目录

javascript - 如何(在哪里)存储网站中实时操作的信息?

php - 在@import 之后覆盖 Bootstrap LESS 变量

html - 在 div 中居中 ul 内容

javascript - 无法点击下拉菜单中的菜单链接

php - Mailchimp 错误 : Bad Request - Your Campaign is not ready to send

apache - Mac 上的 Apache 虚拟主机的通配符域

php - 在 apache tomcat 服务器上使用 CakePHP

javascript - js提交没有值(value)

php - Magento - 基表 core_file_storage 不存在