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]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据