douzha8489 2011-07-04 18:17
浏览 27
已采纳

too long

i have been trying to create a rule for dynamic sub-domains and tried many rules given by other users. I am able to use dynamic sub-domains and they are working fine now.

My sub-domain structure is sub1.sub2.domain.com

Now i want that when a user goes to sub1.sub2.domain.com then the default page must be code.php and not index.php

Also in address bar only sub1.sub2.domain.com should be visible and not sub1.sub2.domain.com/code.php

Also i have to use two level sub-domains not single sub.domain.com

I just need help in creating the rewrite rule which displays code.php when user accesses sub1.sub2.domain.com

Thank You

  • 写回答

1条回答 默认 最新

  • douli1854 2011-07-04 18:24
    关注

    You can try this in .htaccess

    # Provide Specific Index Page (Set the default handler)
    DirectoryIndex code.php
    

    Edit: In your index.php page, before your HTML try something like this:

    if($_SERVER['SERVER_NAME'] == 'example.com' || $_SERVER['SERVER_NAME'] == 'www.example.com'){
         header('Location: /index.php');
    }else{ 
         header('Location: /code.php');
    }
    

    This should look at the server name, including sub-domain and work out what to use from there from memory.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能