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?

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

要实现的结果:

  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
nn

使用.htaccess,它的工作除了“演示” .exemple.com“谁返回502错误。

 #将子域解析为变量
RewriteCond%{REQUEST_FILENAME}!-f 
RewriteCond%{HTTP_HOST}!^ www  
RewriteCond%{HTTP_HOST} ^([^ \。] +)\。([^ \。] +)\。([^ \。] +)$ 
RewriteRule ^(。*)$ / $ 1?subdomain =%  1 
 
#将所有请求映射到distpacher.php中的'path'get变量
RewriteRule ^ distpacher \ .php $  -  [L] 
RewriteCond%{REQUEST_FILENAME}!-f 
RewriteCond%{REQUEST_FILENAME}!-d  
RewriteRule ^(。*)$ /distpacher.php?path=$1 [L,QSA] 
   
 
 

我很难...任何帮助 ,拜托?

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

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]
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题