dseax40600
2017-03-30 12:27
浏览 61
已采纳

.htaccess将子域重写为请求参数

Ho I Can rewrite this request types:

http://name1.domain1.com/        -> index.php?subdomain=name1
http://name2.domain2.org/        -> index.php?subdomain=name2

I need manage subdomain GET variable in php script ( index.php ). I need of generic rule for all domain.

This is my .htaccess file, but it's not working.

RewriteEngine On

# Parse the subdomain as a variable we can access in PHP, and
# run the main index.php script
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST}        !^www
RewriteCond %{HTTP_HOST}         ^([^\.]+)\.([^\.]+)\.([^\.]+)$
RewriteRule ^(.*)$ /$1?subdomain=%1

Thanks.

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

何我可以重写此请求类型:</ p>

  http:  //name1.domain1.com/  - &gt;  index.php?subdomain = name1 
http://name2.domain2.org/  - &gt;  index.php?subdomain = name2 
 </ code> </ pre> 
 
 

我需要在php脚本(index.php)中管理子域GET变量。 我需要所有域的通用规则。< / p>

这是我的.htaccess文件,但它不起作用。</ p>

  RewriteEngine On 
 
#将子域解析为变量我们 可以用PHP访问,
#运行主index.php脚本
RewriteCond%{REQUEST_FILENAME}!-f 
RewriteCond%{HTTP_HOST}!^ www 
RewriteCond%{HTTP_HOST} ^([^ \。] +)\  。([^ \。] +)\。([^ \。] +)$ 
RewriteRule ^(。*)$ / $ 1?subdomain =%1 
 </ code> </ pre> 
 
 <  p>谢谢。</ p> 
 </ div>

1条回答 默认 最新

相关推荐 更多相似问题