本文介绍了内部子域到文件夹重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想即时创建文件夹,但看起来好像我正在使用mod_rewrite即时创建子域.例如

I want to create folders on the fly, but make it seem like I am creating subdomains on the fly using mod_rewrite. e.g.

使用PHP创建"john"文件夹

Create "john" folder using PHP

www.example.com/john/

然后可以访问我在以下位置输入的内容:

Then be able to access whatever I put in there at:

john.example.com

先谢谢您

克里斯

推荐答案

首先,您需要将服务器配置为接受域example.com的任何子域,并将其重定向到还必须接受任何子域的虚拟主机.之后,您可以使用以下规则在内部将该子域重写为具有相同名称的文件夹:

First you need to configure your server to accept any subdomain for your domain example.com and redirect it to your virtual host that as well has to accept any subdomain. After that, you can use the following rule to rewrite that subdomain internally to a folder with the same name:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^([^/.]+)\.example\.com$
RewriteRule ^ %1%{REQUEST_URI} [L]

这篇关于内部子域到文件夹重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 13:08
查看更多