2

我正在开发一个带有 htaccess 规则的网站。这是网址结构:

example.com
example.com/index.php/login
example.com/index.php/foo
demos.example.com

对于上面的最后一个 url (demos.example),我想显示 .htaccess 的内容example.com/index.php/demos,因此,我创建了一个 .htaccess 文件,如下所示:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www\.)?demos.example.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/demos [L]

当我浏览demos.example.com索引页面时显示(example.com),因为没有发生任何事情。我希望我的解释很清楚。

  • 我已阅读此主题,但此解决方案执行“浏览器重定向”,这不是想法。
  • 使用此示例不会产生任何结果:显示的是索引而不是 index.php/demos

更新

如果我使用 .htaccess 如下:

RewriteCond %{HTTP_HOST} ^(www\.)?demos\.example\.com 
RewriteRule ^(.*)$ index.php/demos/$1 [L]

...这使得浏览器显示一个500 internal server error. 查看日志,它会打印以下消息:

[Thu Dec 06 15:06:24 2012] [error] [client 201.192.30.254] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer: http://example.com/
[Thu Dec 06 15:06:24 2012] [debug] core.c(3112): [client 201.192.30.254] r->uri = /index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/, referer: http://example.com/
[Thu Dec 06 15:06:24 2012] [debug] core.c(3118): [client 201.192.30.254] redirected from r->uri = /index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/, referer: http://example.com/
[Thu Dec 06 15:06:24 2012] [debug] core.c(3118): [client 201.192.30.254] redirected from r->uri = /index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/, referer: http://example.com/
[Thu Dec 06 15:06:24 2012] [debug] core.c(3118): [client 201.192.30.254] redirected from r->uri = /index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/, referer: http://example.com/
[Thu Dec 06 15:06:24 2012] [debug] core.c(3118): [client 201.192.30.254] redirected from r->uri = /index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/, referer: http://example.com/
[Thu Dec 06 15:06:24 2012] [debug] core.c(3118): [client 201.192.30.254] redirected from r->uri = /index.php/demos/index.php/demos/index.php/demos/index.php/demos/index.php/demos/, referer: http://example.com/
[Thu Dec 06 15:06:24 2012] [debug] core.c(3118): [client 201.192.30.254] redirected from r->uri = /index.php/demos/index.php/demos/index.php/demos/index.php/demos/, referer: http://example.com/
[Thu Dec 06 15:06:24 2012] [debug] core.c(3118): [client 201.192.30.254] redirected from r->uri = /index.php/demos/index.php/demos/index.php/demos/, referer: http://example.com/
[Thu Dec 06 15:06:24 2012] [debug] core.c(3118): [client 201.192.30.254] redirected from r->uri = /index.php/demos/index.php/demos/, referer: http://example.com/
[Thu Dec 06 15:06:24 2012] [debug] core.c(3118): [client 201.192.30.254] redirected from r->uri = /index.php/demos/, referer: http://example.com/
[Thu Dec 06 15:06:24 2012] [debug] core.c(3118): [client 201.192.30.254] redirected from r->uri = /, referer: http://example.com/ 
4

1 回答 1

1

试试这个:

RewriteCond %{HTTP_HOST} ^(www\.)?demos\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/index.php/demos/$1 [L]
于 2012-12-06T21:53:47.423 回答