我希望收到http://user1.domain.com的请求:
现在我有以下内容.htaccess:
RewriteEngine On
RewriteBase /
# Protect the htaccess file
<Files .htaccess>
Order Allow,Deny
Deny from all
</Files>
# Disable directory browsing
Options All -Indexes
RewriteCond %{HTTP_HOST} !^www.domain.com
RewriteCond %{HTTP_HOST} !^admin.domain.com
RewriteCond %{HTTP_HOST} ([^.]+).domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/site-client/site.php?site=%1 [L]
成功调用http://www.domain.com/site-client/site.php?site=user1网址,但会向用户显示该网址。 我怎么能避免这个?
答案 0 :(得分:1)
你需要摆脱yor http://www.domain.com
目标的RewriteRule
部分。它告诉mod_rewrite你想要302重定向。所以你的规则应该是这样的:
RewriteCond %{HTTP_HOST} !^www.domain.com
RewriteCond %{HTTP_HOST} !^admin.domain.com
RewriteCond %{HTTP_HOST} ([^.]+).domain.com [NC]
RewriteCond %{REQUEST_URI} !^/site-client/site.php
RewriteRule ^(.*)$ /site-client/site.php?site=%1 [L]
编辑:您还需要检查以防止规则循环