子域中的.htaccess

时间:2010-11-23 03:06:46

标签: apache .htaccess mod-rewrite

我正在尝试按如下方式设置子域名:

http://subdomain.domain.com应该加载真正的http://subdomain.domain.com/index.php/contest/

http://subdomain.domain.com/stepone应该加载真正的http://subdomain.domain.com/index.php/contest/stepone

http://subdomain.domain.com/images/example.jpg应正常加载http://subdomain.domain.com/images/example.jpg

我已经将这一切设置好并且在主域上的子目录中工作,但现在我正在尝试在子域上执行它已停止工作。

这是我的.htaccess:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|stylesheets|javascript|email|robots\.txt|test\.php|terms\.html)
RewriteRule ^(.*)$ /index\.php/contest/$1 [L]

请帮助我!

3 个答案:

答案 0 :(得分:1)

重写规则是否有效?即你有AllowOverride All或虚拟主机的东西,按照:

另外,请看看Gumbo关于这个问题的评论:

答案 1 :(得分:1)

Drupal .htaccess文件是将/?q = query映射到/ query的一个很好的例子,但不重定向提供显式文件/目录匹配的东西。这是Drupal的.htaccess的相关片段,其中?q =已更改为index.php / contest /.

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/contest/$1 [L,QSA]

如果您需要限制域名以使其不会正常重定向,而只是从一个域名重定向,请在RewriteRule之前插入:

RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com$ [NC]

答案 2 :(得分:0)

我想我找到了答案:

RewriteRule ^(.*)$ subdomain.domain.com/index\.php/contest/$1 [L, P]

有什么理由我不应该像这样使用强制代理吗? (它会减慢速度吗?)

感谢您的回答。