2013-10-29 16:22
浏览 121

.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.

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

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.

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

Thanks in advance,

Isaiah v. Hunen

图片转代码服务由CSDN问答提供 功能建议

这个问题可能已被问过一千多次,但我已经尝试过这么多的脚本,并用Google搜索 很久没有找到任何东西,我想,让我们问一下。

我只想将 m.daltonempire.nl 重定向到 daltonempire.nl/m / 没有用户看到URL更改。

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

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


Isaiah v.Hunen

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • doulao2128 2015-03-31 08:11

    I have set CNAME of my sub domain below:


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

    Formerly I need to use this url to call wordpress:


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


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

    Finally I got .htaccess setting that is work:

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

    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]

    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.

    解决 无用
    打赏 举报
  • douhulao7642 2013-10-29 16:27

    Try this example:

    RewriteCond %{HTTP_HOST} ^([^/.]+)\.example\.com$ 
    RewriteCond %1 !^(www|ftp|mail)$ [NC]
    RewriteRule (.+)$ "http://example.com/%1" [L,P]

    Any requests http://test.example.com will be mapped to http://example.com/test/...

    Try googling dynamic subdomain with php and htaccess to get better search results.

    解决 无用
    打赏 举报
  • drxzpo70788179614 2013-10-29 16:27

    Add this to your .htaccess in your web root / directory

    RewriteEngine on
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^m\.daltonempire\.nl$ [NC]
    RewriteCond %{REQUEST_URI} !^/m(/|$) [NC]
    RewriteCond %{REQUEST_FILENAME} !-d # not a dir
    RewriteCond %{REQUEST_FILENAME} !-f # not a file
    RewriteRule ^(.*)$ m/$1 [L]

    The %{REQUEST_FILENAME} conditions would let you access /exists.php and not rewrite it to /m/exists.php. Remove those two if you want to rewrite even if that may potentially override existing files and directories.

    解决 无用
    打赏 举报

相关推荐 更多相似问题