htaccess的重定向域子目录不改变网址 [英] .htaccess redirect domain to subdirectory without changing URL

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

问题描述

我有以下设置: - > domain1.com是我的主要领域,也文档根目录 - > domain2.com是被注册为别名域(意味着它不完全一样domain1.com)另一个域,我有多个这些域

I have the following setup: -> domain1.com is my main domain and also document root -> domain2.com is another domain which is registered as an alias domain (means it does exactly the same as domain1.com), I have multiple of those domains.

当我现在想重定向域名的东西,我通常用它来重定向域别的东西(如外部网站):

when I now want to redirect that domain to something I usually use this to redirect the domain to something else (like an external website):

RewriteCond %{HTTP_HOST} ^(www\.)?domain2.com$ [NC]
RewriteRule ^(.*) http://somewiredisp.com/user/bla/$1 [L,R]

这是通常使用的,如果我注册的人谁需要一个漂亮的URL为自己的论坛或任何一个域。工程就像一个魅力 - 唯一的问题将是在浏览器改变地址栏,但我读过,就没有办法做到这一点与外部URL,并且由于没有人抱怨它的 I 的是与它的罚款。

this is usually used if I register a domain for someone who needs a nice url for their forums or whatever. Works like a charm - the only "problem" would be that the address bar in the browser changes, but I've read that there would be no way to do that with external URLs, and since no one ever complained about it I am fine with it.

不过,现在我想某些URL链接到一个子目录如果没有URL在地址栏中改变。

However, now I would like to link some url to a subdirectory WITHOUT the url changing in the address bar.

domain2.com - > domain1.com/subdir(或domain2.com/subdir - 这并不重要,因为它是一个别名域)

domain2.com -> domain1.com/subdir (or domain2.com/subdir - that doesn't matter, since it's an alias domain).

我目前的做法是

RewriteCond %{HTTP_HOST} ^(www\.)?domain2.com$ [NC]
RewriteRule ^(.*) http://domain1.com/subdir/ [P]

不工作(错误404) - 如果我叫domain1.com/subdir/直接,如果作品显然

which doesn't work (Error 404) - if I call domain1.com/subdir/ directly if works obviously.

我也试过

RewriteRule ^(.*) http://domain2.com/subdir/ [P]
RewriteRule ^(.*) /subdir/ [P]
RewriteRule ^(.*) http://domain1.com/subdir/index.html [P]

都具有相同的结果。

all with the same result.

也许这只是一个简单的错误,但我目前无言以对:/

maybe it's just a simple mistake but I am currently clueless :/

推荐答案

您可以使用此规则:

RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com$ [NC]
RewriteRule !^subdir/ /subdir%{REQUEST_URI} [L,NC]

这将preFIX为 domain2.com 每个请求与 /子目录,如果它已不存在

This will prefix every request for domain2.com with /subdir if it is not already there.

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

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