dongshu4755 2014-12-24 04:01
浏览 21
已采纳

.htaccess - 子域和路径为GET var

Results to achieve :

http://example.com/                   -> /websites/dispatcher.php
http://another-example.com/           -> /websites/dispatcher.php
http://demo.example.com/              -> /websites/dispatcher.php?subdomain=demo
http://demo.example.com/cat/page.html -> /websites/dispatcher.php?subdomain=demo&path=/cat/page.html

With the .htaccess i have, it's working except for the "demo.exemple.com" who return a 502 error.

# Parse the subdomain as a variable
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST}        !^www
RewriteCond %{HTTP_HOST}         ^([^\.]+)\.([^\.]+)\.([^\.]+)$
RewriteRule ^(.*)$ /$1?subdomain=%1

# Map all requests to the 'path' get variable in distpacher.php
RewriteRule ^distpacher\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /distpacher.php?path=$1 [L,QSA] 

I'm having a hard time... any help, please?

  • 写回答

1条回答 默认 最新

  • dpkt17803 2014-12-24 06:36
    关注

    Replace your 2 rules by these 2 rules:

    # Map all requests to the 'path' get variable in dispatcher.php
    RewriteCond %{HTTP_HOST} !^www [NC]
    RewriteCond %{HTTP_HOST} ^([^.]+)\.[^.]+\.[^.]+$
    RewriteRule ^/?$ /dispatcher.php?subdomain=%1 [L,QSA]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{HTTP_HOST} !^www [NC]
    RewriteCond %{HTTP_HOST} ^([^.]+)\.[^.]+\.[^.]+$
    RewriteRule ^(.+)$ /dispatcher.php?subdomain=%1&path=$1 [L,QSA]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度