重定向子目录子站点htaccess的 [英] Redirecting Subdirectory to Subdomain with htaccess

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

问题描述

我是比较新的使用的.htaccess,并从来没有这样做,除了我所在线阅读编写任何代码。我使用BlueHost的,我想重定向我的博客子目录的子域。例如:我想重定向www.example.com/blog到blog.example.com

I'm relatively new to using .htaccess, and have never done any coding besides what I've read online. I'm using Bluehost, and I'd like to redirect my blog subdirectory to a subdomain. Example: I'd like to redirect www.example.com/blog to blog.example.com.

我已经有code到位,随时补充WWW。要在根文件夹我的博客地址的开始,但我不知道如何使用code在.htaccess完成上述重定向。任何帮助将是AP preciated!

I already have code in place to always add www. to the beginning of my blog address in the root folder, but I don't know how to accomplish the above redirect by using code in .htaccess. Any help would be appreciated!

推荐答案

很多网站的主机今天提供了一个简单的FPGA实现子站点创建自己的管理面板。你只需要去那里,选择子域名,然后将它指向的目录树中的。

A lot of web hosts today provide an easy implemention for subdomain creation in their administration panels. You just need to to go there, choose you subdomain name, and then point it to a directory in your tree.

如果你不能,那么这将是一个更复杂一点(您将需要解决的子域名服务器的IP,配置一些虚拟主机...等),你可能没有足够的权限来做到这一点(除非你是一个专用的服务器上)。

If you can't, then it will be a little more complicated (You will need to resolve that subdomain to your server ip, configure some virtual hosts ... etc) and you may not have enough privileges to do that (unless you are on a dedicated server).

编辑2

要请求重定向到www.example.com/blog~~V到blog.example.com,试试这个:

To redirect requests to www.example.com/blog to blog.example.com, try this :

RewriteEngine on

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^blog/(.*)$ http://blog.example.com/$1 [L,QSA,R=301]

RewriteCond %{HTTP_HOST} ^blog\.example\.com$
RewriteCond %{REQUEST_URI} !^blog/
RewriteRule ^(.*)$ /blog/$1 [L,QSA]

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

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