如果用户请求子域WP [重复],则重定向到子域

问题描述 投票:0回答:1

这个问题在这里已有答案:

我在主域example.com中安装WP,并且有.htaccess文件:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

</IfModule>

# END WordPress

如何将请求{subdomain} .example.com的用户重定向到app.example.com/{subdomain}但是如果他们只是想让example.com像现在这样给他们index.php文件?

另外如何在浏览器中保留{subdomain} .example.com而不是显示app.example.com/{subdomain}?

更新:我的通配符子域已经重定向到主域...

php wordpress laravel .htaccess ssl
1个回答
0
投票

即使你可以用PHP或JS做到这一点

public_html/subdomain/index.php的顶部添加这些行

<?php
  if($_SERVER[HTTP_HOST] == "example.com"){
    header("location:http://sub.example.com");
    exit();
 }

由于您使用的是WordPress,最好在wp-blog-header.php的顶部使用此代码片段现在您已经完成了设置。

© www.soinside.com 2019 - 2024. All rights reserved.