简体   繁体   English

将子域重定向到子目录,而无需更改多个WordPress的URL

[英]Redirect Subdomain to Subdirectory without changing URL multiple WordPress

I have my folders in public_html like this, 我的文件夹在public_html中是这样的,

/ - root public html for example.com [has wordpress in it] /a/ - this has another wordpress installed and a.example.com should be pointed to this directory /b/ - again wordpress for b.example.com /-example.com的根公共html [其中包含wordpress] / a /-这已经安装了另一个wordpress,并且a.example.com应指向该目录/ b /-b.example.com再次是wordpress

I tried this code, 我尝试了这段代码,

RewriteEngine On
RewriteCond %{HTTP_HOST} ^a\.example\.com$
RewriteCond %{REQUEST_URI} !^/a/
RewriteRule (.*) /a/$1

but it doesn't work. 但这不起作用。 I use VestaCP control panel and don't want to add site for each subdomain instead have it all under the same root directory. 我使用VestaCP控制面板,不想为每个子域添加站点,而是将其全部放在同一根目录下。

I also noticed that going to a 404 page like example.com/a/somenotfoundpage will show me the 404 page of the root wordpress installation and not /a/ installation 我还注意到,转到example.com/a/somenotfoundpage之类的404页面将显示root wordpress安装而不是/ a /安装的404页面。

How can it be fixed inside .htaccess ? 如何将其固定在.htaccess中? /a/ and /b/ are both multi site installation each and / is normal installation / a /和/ b /都是多站点安装,/是正常安装

the url for the /a/ and /b/ are set to a.example and b.example in wordpress settings / a /和/ b /的网址在wordpress设置中设置为a.example和b.example

EDIT 编辑

VestaCP is set to redirect *.example.com to example.com. VestaCP设置为将* .example.com重定向到example.com。 (I have used it as an aliases when adding the site, and visiting a.example.com shows me example.com content without the address changing in the address bar) (添加网站时,我已将其用作别名,访问a.example.com会显示example.com内容,而地址栏中的地址没有更改)

In your wp-config.php file, there's a line that says Subdomains and it's set to 'false' right now. 在您的wp-config.php文件中,有一行显示“子域”,并且现在将其设置为“ false”。 Change it to true and your site will flip over. 将其更改为true,您的网站将翻转。

Now that said... You may want to consider .htaccess redirecting the old URLs to the new ones. 如此说来...您可能要考虑.htaccess将旧URL重定向到新URL。 But it should work just that easily. 但是它应该那样容易工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM