的.htaccess重写子域目录,并保持子域网址 [英] .htaccess rewrite subdomain to directory and keep subdomain in url

查看:184
本文介绍了的.htaccess重写子域目录,并保持子域网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用的.htaccess重写一个子域到一个子目录,但保持在子域这样的网址:

I need to rewrite a subdomain to a subdirectory using .htaccess but keep the subdomain in the url like this:

在浏览器中访问网址: sub1.domain.com

Visited url in browser: sub1.domain.com

历任网址: sub.domain.com/sub1 /

我尝试以下

RewriteCond %{HTTP_HOST} ^subdomain.domain.com
RewriteRule ^(.*)$ http://subdomain.domain.com/subdomain/$1 [L,NC,QSA]

但是这会导致无限循环。我知道,这将是更容易PHP这样做,但有没有使用的.htaccess这方面的任何解决方案?

but this leads to an endless loop. I know that it would be easier to do this by php but is there any solution for this with using .htaccess?

推荐答案

您可以使用文档根目录的规则:

You can use this rule in document root:

RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com$ [NC]
RewriteRule ^((?!sub1/).*)$ /sub1/$1 [L,NC]

这篇关于的.htaccess重写子域目录,并保持子域网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆