<分区>
<分区>
我在主域 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 或 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
的顶部使用此代码片段,现在您已准备就绪。
关于php - 如果用户请求子域 WP,则重定向到子域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48034350/