.htaccess - 将子域重定向到文件夹 [英] .htaccess - Redirect subdomain to folder

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

问题描述

这个问题可能已经被问过一千多次了,但我已经尝试了很多脚本,搜索了很长时间却一无所获,我想,我们就问吧.

This question has probably been asked for over a thousand times, but I've tried so many scripts, and googled so long while finding nothing, I thought, let's just ask.

我只是希望 m.daltonempire.nl 被重定向到 daltonempire.nl/m/ 而不让用户看到 URL 更改.

I simply want m.daltonempire.nl to be redirected to daltonempire.nl/m/ without the user seeing the URL change.

因此,如果请求 m.daltonempire.nl/hello.php,我希望用户继续看到这个 URL,而给出的页面实际上是 daltonempire.nl/m/hello.php.

So if m.daltonempire.nl/hello.php is requested, I want the user to keep seeing this URL, while the page given is actually daltonempire.nl/m/hello.php.

注意:我不想要 www.,所以只需 http://m.daltonempire.nl

Note: I do not want www., so simply http://m.daltonempire.nl

提前致谢,

以赛亚诉胡南案

推荐答案

我在下面设置了我的子域的 CNAME:

I have set CNAME of my sub domain below:

blog.mydomain.com

安装在根目录下的文件夹 /blog/ 中的我的 wordpress.

to my wordpress that installed in folder /blog/ under root directory.

以前我需要用这个url来调用wordpress:

Formerly I need to use this url to call wordpress:

http://blog.mydomain.com/blog/

这是丑陋的.我尝试了很多代码来重定向:

which is ugly. I have tried many code to redirect:

http://blog.mydomain.com/

到文件夹,以便我可以将其用作我的 wordpress 网址.

to the folder so I can use it as my wordpress url.

最后我得到了有效的 .htaccess 设置:

Finally I got .htaccess setting that is work:

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^blog\.mydomain\.com$
    RewriteCond %{REQUEST_URI} !^/blog/
    RewriteRule (.*) /blog/$1

我还有 CNAME 其他子域:http://forum.mydomain.com 到文件夹 /forum/mybb/ 中的 mybb 安装,所以 .htaccess 需要将 [L] 放在每个 RewriteRule 代码上,如下所示.

I have also CNAME other subdomain: http://forum.mydomain.com to mybb installation in folder /forum/mybb/ so the .htaccess need to put [L] on each of RewriteRule code as below.

    RewriteEngine On

    RewriteCond %{HTTP_HOST} ^forum\.tophyips\.info$
    RewriteCond %{REQUEST_URI} !^/forum/mybb/
    RewriteRule (.*) /forum/mybb/$1 [L]

    RewriteCond %{HTTP_HOST} ^blog\.tophyips\.info$
    RewriteCond %{REQUEST_URI} !^/blog/
    RewriteRule (.*) /blog/$1 [L]

如果您想使用代码,请不要忘记在应用程序配置文件中设置站点 url 和 cookie 路径,按照设置使重定向正常工作.

In case you want to use the code please don't forget to set the site url and cookie path in the application config file follow to the setting to make the redirection work properly.

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

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