繁体   English   中英

为什么RewriteRule在.htaccess中没有R标志的情况下无法工作

[英]Why RewriteRule not working without R flag in .htaccess

我在Web根的project文件夹中有一个Codeigniter项目。

www
www/.htaccess
www/project/.htaccess ( here are its contents https://pastebin.com/qBbZ0REj )

www / .htaccess

 RewriteEngine On
 RewriteRule ^pg/fetchPG/(.*)$ /project/product_groups/fetchPG/$1 [L]

www/project/.htaccess相关部分

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

如果我做

http://localhost/pg/fetchPG/?groupid=26&response=html&mode=graph&response=html

它应该显示的内容

http://localhost/project/product_groups/fetchPG/?groupid=26&response=html&mode=graph&response=html

但这只是向我显示了Codeigniter的404页。

我以为Querystring不见了,但是我尝试在该404页中打印$ _GET,很好,它来了。

我用[L, R]替换了[L] ,它可以工作,它重定向到该URL,但是我不希望用户看到最终的URL。

PS:我有专用的服务器,我可以控制一切,请提出是否还有其他方法可以实现我的目标?

它与R|redirect标志一起工作的原因是,通过重定向,客户端发送了一个新请求,结果REQUEST_URI发生了变化。

我假设将CodeIgniter配置为查看REQUEST_URI而不是QUERY_STRING ,这与www/project/.htaccess的规则相对应

RewriteRule ^(.*)$ index.php?/$1 [L]

要解决此问题,请按照用户指南中的query_stringuri_protocol更改为uri_protocol

最后,将以下新项添加到配置文件(并在需要时编辑选项):

 /* |------------------------------------------------ | URI PROTOCOL |------------------------------------------------ | | This item determines which server global | should be used to retrieve the URI string. The | default setting of "auto" works for most servers. | If your links do not seem to work, try one of | the other delicious flavors: | | 'auto' Default - auto detects | 'path_info' Uses the PATH_INFO | 'query_string' Uses the QUERY_STRING */ $config['uri_protocol'] = "auto"; 

在您的情况下,这看起来应该像

$config['uri_protocol'] = "query_string";

为了保留查询字符串,您可以尝试使用path_info ,例如

$config['uri_protocol'] = "path_info";

但您还必须将www/project/.htaccess的重写规则更改为

RewriteRule ^(.*)$ index.php/$1 [L]

请注意,不再有问号( ? )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM