如果用户请求子域WP

时间:2017-12-30 13:26:18

标签: php wordpress laravel .htaccess ssl

我在主域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}?

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

1 个答案:

答案 0 :(得分: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的顶部使用此代码段,现在您已经完成了设置。

相关问题