gpt4 book ai didi

php - REQUEST_URI 不会被使用 APACHE RewriteRule 覆盖吗?

转载 作者:可可西里 更新时间:2023-10-31 22:52:13 25 4
gpt4 key购买 nike

问题:

我正在使用 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'] 将请求路由到适当的 Controller 代码。在这种情况下,它会将其路由到 base 索引 Controller ,而不是“invites” Controller 。

事实:

我正在使用的 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]

在 index.php 中,我这样做:

var_dump($_SERVER);

我得到:

'REQUEST_URI' => string '/',
'QUERY_STRING' => string 'kohana_uri=invites/index.php&kohana_uri=invites/invite'
'REDIRECT_QUERY_STRING' => string 'kohana_uri=invites/invite'

所以 mod_rewrite 不会修改 REQUEST_URI?

需要:

'REQUEST_URI' => 'invites/invite',
'QUERY_STRING' => string 'kohana_uri=invites/invite',

我如何获得它?

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

重写日志条目:-

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]

最佳答案

1.) 如果手动调用此链接是否有效? http://www.mydomain.com/invites/invite

2.) RewriteCond %{HTTP_HOST} !^www.mydomain.com$需要像 RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$

3.) RewriteRule .* index.php?kohana_uri=$0 [PT,QSA,L] 是一个无限循环,因为 index.php 适合正则表达式 .*,也是。

4.) 您需要 R 标志将用户重定向到邀请/RewriteRule ^(.*)$ invites/$1 [R=301]%{REQUEST_URI} 与浏览器地址栏中的 uri 相同。

5.) 如果您不想重定向访问者,您可以“破解”kohana 系统并设置 $_SERVER['REQUEST_URI'] = $_GET['myURI']; 在index.php 的第一行,如果这是让它运行的唯一选项。 myURI 可以根据需要通过 mod_rewrite 填充。

关于php - REQUEST_URI 不会被使用 APACHE RewriteRule 覆盖吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5864810/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com