2017-06-04 72 views
0

我在web根目录的project文件夹中有一个Codeigniter项目。为什么RewriteRule不能在没有R标志的情况下工作.htaccess

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丢失了,但我试图在该页面中打印$ _GET,这很好,它一直在。

我将[L]替换为[L, R],它起作用,它重定向到该URL,但我不希望用户看到最终的URL。

PS:我有专门的服务器,我有一切控制权,请建议是否有其他方法来帮助我实现目标?

+0

在你的文件系统的根目录下是否有'/ project'文件夹? –

+0

@DusanBajic文件系统的根?不,'project'文件夹在'www'中,意思是它在'www/project'中的位置..请参阅问题,我试图解释我有的目录结构 – Umair

+0

文档是否位于'www'或'www/project '? –

回答

1

它与R|redirect标志一起使用的原因是,用重定向客户端发送一个新请求,结果REQUEST_URI更改。

我假定,笨被配置为查看REQUEST_URI而不是在QUERY_STRING,其对应于该规则在www/project/.htaccess

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

为了修正它,作为user guide

描述改变 uri_protocolquery_string

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

/* 
|------------------------------------------------ 
| 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] 

注意,有没有问号(?)了。

+0

你的建议'$ config ['uri_protocol'] =“query_string”;'带我的代码来纠正控制器,但是在这个过程中,所有查询字符串都会丢失,它是空的。 '$ _GET'只有'/ product_groups/fetchPG /'在里面... – Umair

+0

我甚至试过'[L,QSA]'但没有查询字符串参数,全部丢失。 – Umair

+0

它应该保留查询字符串,尽管您可能会尝试'uri_protocol = path_info'。 –

相关问题