首页 > 解决方案 > 如何根据子域(如 wordpress 主题)更改带有文件的根文件夹

问题描述

我花了几天时间研究互联网,但找不到答案。

我有 abc.com 网站,我在 .htaccess 的帮助下获得了子域地址,但是如何根据子域显示不同的主题。

解释。用户创建子域flower.abc.com 和vegetable.abc.com 等我从数据库php 中根据子域获取用户选择的主题,但我不知道如何更改根链接和根目录

目录

/index.php  
     //theme folder   
flower/index.php   
....../css/  
...../js/

vegetable/index.php  
....../css/   
...../js/  
etc more theme available

但是当用户vegetable.abc.com选择主题蔬菜然后显示主题蔬菜当用户选择花卉主题然后显示花卉主题。

vegetable.abc.com/vegetable/index.php  
to   
vegetable.abc.com/index.php

标签: phphtmlcss

解决方案


你可以使用 .htaccess

vegetable.abc.com/vegetable/index.php   

vegetable.abc.com/index.php

.httaccess 文件中的规则

RewriteEngine On

RewriteCond %{HTTP_HOST} ^vegetable\.abc\.com\/vegetable\/index\.php [NC]
RewriteRule ^$ https://vegetable.abc.com/index.php [R=302,L]

虚拟主机

<VirtualHost *:80>
    ServerAlias *.example.com
    VirtualDocumentRoot /var/www/%1/
</VirtualHost>

推荐阅读