子域名重定向与htaccess的没有在地址栏中改变URL [英] Subdomain redirect with htaccess without changing URL in the address bar

查看:137
本文介绍了子域名重定向与htaccess的没有在地址栏中改变URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置子我的虚拟主机是这样的:

  en.domain.com指向文件夹/ EN /
 

不过,在地址栏输入时,en.domain.com,网址修改

  domain.com/en/
 

如果我继续导航,假设到文件夹AAA,网址变成

  domain.com/en/aaa/
 

有没有一种方法,使子域留在地址栏中,这样的:

  en.domain.com/aaa/
 

解决方案

我什么都试过,没有人能帮助我。经过反复研究,我发现了这一点,它为我工作。所以在这里我自己的答案,这可能帮助别人寻找同样的事情。

这将使该显示的子域(en.domain.com)的网址不会在地址栏中改变,即使有人进入domain.com/en/这将重写URL为en .domain.com:

  RewriteEngine叙述上

的RewriteCond%{HTTP_HOST} ^域\ .COM $
重写规则^恩(/(.*))? http://en.domain.com/$2 [QSA,L,R = 301]
 

这将打破你的网站的路径,造成了风格和图像将不会显示。因此,你需要把这个在你的HTML code网站的每个页面上,根据每个页面在您的网站的结构位置:

有关文件夹页恩:

 < HEAD>
<基地的HREF =htt​​p://domain.com/en//>
< /头>
 

有关文件夹中的AAA的页面:

 < HEAD>
<基地的HREF =htt​​p://domain.com/en/aaa//>
< /头>
 

有关文件夹BBB的页面:

 < HEAD>
<基地的HREF =htt​​p://domain.com/en/aaa/bbb//>
< /头>
 

欢迎您! : - )

I set up a subdomain on my web host like this:

en.domain.com     pointing to the folder     /en/

But when entering "en.domain.com" in the address bar, the URL changes to

domain.com/en/

And if I navigate further, let's say to folder "aaa", the URL turns into

domain.com/en/aaa/

Is there a way to make the subdomain stay in the address bar, like this?:

en.domain.com/aaa/

解决方案

I tried everything and nobody could help me. After much research, I found this and it works for me. So here my own answer, that may help others searching for the same thing.

This will make that the URL showing the subdomain ("en.domain.com") doesn't change in the address bar and even if someone enters "domain.com/en/" it will rewrite the URL to "en.domain.com":

RewriteEngine On

RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteRule ^en(/(.*))? http://en.domain.com/$2 [QSA,L,R=301]

This will break the paths of your site, causing that styles and images won't show. Therefore you need to put this in your HTML code on every page of your site, according to the location of each page in the structure of your site:

For the page in folder "en":

<head>
<base href="http://domain.com/en/" />
</head>

For the page in folder "aaa":

<head>
<base href="http://domain.com/en/aaa/" />
</head>

For the page in folder "bbb":

<head>
<base href="http://domain.com/en/aaa/bbb/" />
</head>

You are welcome! :-)

这篇关于子域名重定向与htaccess的没有在地址栏中改变URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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