dswu26846 2013-10-29 16:22
浏览 132
已采纳

.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

  • 写回答

3条回答 默认 最新

  • doulao2128 2015-03-31 08:11
    关注

    I have set CNAME of my sub domain below:

    blog.mydomain.com

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

    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/

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 xshell无法连接提示ssh服务器拒绝密码
  • ¥15 AT89C52单片机C语言关于串口通信的位操作
  • ¥20 需要步骤截图(标签-服务器|关键词-map)
  • ¥50 gki vendor hook
  • ¥15 灰狼算法和蚁群算法如何结合
  • ¥15 这是一个利用ESP32自带按键和LED控制的录像代码,编译过程出现问题,请解决并且指出错误,指导如何处理 ,协助完成代码并上传代码
  • ¥20 stm32f103,hal库 hal_usart_receive函数接收不到数据。
  • ¥20 求结果和代码,sas利用OPTEX程序和D-efficiency生成正交集
  • ¥50 adb连接不到手机是怎么回事?
  • ¥20 抓取数据时发生错误: get_mooncake_data() missing 1 required positional argument: 'driver'的问题,怎么改出正确的爬虫代码?