使用APACHE RewriteRule不会覆盖REQUEST_URI?

Ajo*_*joy 10 php apache dns mod-rewrite kohana

问题:

我使用Kohana/PHP为其他公司开发托管网站.我让客户在他们的DNS服务器中输入CNAME条目以指向我的域.例如.http://invites.somecompany.com指向http://www.mydomain.com.

因此,我的apache服务器上的%{HTTP_HOST}条目是'invites.somecompany.com'

我想重写 http://invites.somecompany.com/invitehttp://www.mydomain.com/invites/invite

即使Apache似乎这样做,$ _SERVER ['REQUEST_URI']仍然是"/".问题是Kohana使用$ _SERVER ['REQUEST_URI']将请求路由到适当的控制器代码.在这种情况下,它将它路由到基本索引控制器,而不是" 邀请 "控制器.

事实:

我正在使用的Apache mod_rewrite指令(在.htaccess文件中): -

RewriteCond %{HTTP_HOST} !^www.mydomain.com$
RewriteCond %{REQUEST_URI} !.*invites.*
RewriteRule ^(.*)$ invites/$1

# For Kohana
RewriteRule .* index.php?kohana_uri=$0 [PT,QSA,L]
Run Code Online (Sandbox Code Playgroud)

在index.php中,我这样做:

var_dump($_SERVER);
Run Code Online (Sandbox Code Playgroud)

我得到:

'REQUEST_URI' => string '/',
'QUERY_STRING' => string 'kohana_uri=invites/index.php&kohana_uri=invites/invite'
'REDIRECT_QUERY_STRING' => string 'kohana_uri=invites/invite'
Run Code Online (Sandbox Code Playgroud)

那么mod_rewrite不会修改REQUEST_URI?

需要:

'REQUEST_URI' => 'invites/invite',
'QUERY_STRING' => string 'kohana_uri=invites/invite',
Run Code Online (Sandbox Code Playgroud)

我怎么做到的?

======================编辑

重写日志条目: -

strip per-dir prefix: /Users/project/invite -> invite
 applying pattern '^(?:application|modules|system)\b.*' to uri 'invite'
 strip per-dir prefix: /Users/project/invite -> invite
 applying pattern '\.git' to uri 'invite'
 strip per-dir prefix: /Users/project/invite -> invite
 applying pattern '^(.*)$' to uri 'invite'
 rewrite invite -> invites/invite
 add per-dir prefix: invites/invite -> /Users/project/invites/invite
 strip per-dir prefix: /Users/project/invites/invite -> invites/invite
 applying pattern '.*' to uri 'invites/invite'
 rewrite invites/invite -> index.php?kohana_uri=invites/invite
 add per-dir prefix: index.php -> /Users/project/index.php
 strip document_root prefix: /Users/project/index.php -> /index.php
 internal redirect with /index.php [INTERNAL REDIRECT]
 strip per-dir prefix: /Users/project/index.php -> index.php
 applying pattern '^(?:application|modules|system)\b.*' to uri 'index.php'
 strip per-dir prefix: /Users/project/index.php -> index.php
 applying pattern '\.git' to uri 'index.php'
 strip per-dir prefix: /Users/project/index.php -> index.php
 applying pattern '^(.*)$' to uri 'index.php'
 rewrite index.php -> invites/index.php
 add per-dir prefix: invites/index.php -> /Users/project/invites/index.php
 strip per-dir prefix: /Users/project/invites/index.php -> invites/index.php
 applying pattern '.*' to uri 'invites/index.php'
 rewrite invites/index.php -> index.php?kohana_uri=invites/index.php
 add per-dir prefix: index.php -> /Users/project/index.php
 initial URL equal rewritten URL: /Users/project/index.php [IGNORING REWRITE]
Run Code Online (Sandbox Code Playgroud)

bra*_*dym -1

删除了我之前的答案,因为它完全错误。感谢您的文档链接,学到了新东西。

删除 QSA 标志:

# For Kohana
RewriteRule .* index.php?kohana_uri=$0 [PT,L]
Run Code Online (Sandbox Code Playgroud)

根据文档

'qsappend|QSA'(查询字符串附加) 该标志强制重写引擎将替换字符串的查询字符串部分附加到现有字符串,而不是替换它。当您想要通过重写规则向查询字符串添加更多数据时,请使用此选项。

第一次应该就注意到了。