仅为url重写路径设置htaccess php_value

时间:2013-05-29 09:46:03

标签: codeigniter .htaccess

我想仅为特定的url(重写)路径设置php_value标志。我正在使用htaccess来实现这一目标。我正在使用的框架是CodeIgniter,因此有一个htaccess文件和url路由由php处理。

只有网站的后端应该有php_value max_input_vars 3000。网址为http://www.example.com/admin/dashboard

我在htaccess文件中考虑过这个问题:

<Location /website.com/admin>
    php_value max_input_vars 20000
</Location>

3 个答案:

答案 0 :(得分:4)

好的,因为您无法将Apache升级到最新版本,只需解决方法即可实现此条件设置。

1 - 在DOCUMENT_ROOT运行此命令以创建index.php的{​​{1}}符号链接

__anything.php

2 - 将新代码放在ln -s index.php __anything.php 正下方的DOCUMENT_ROOT/.htaccess行。整体RewriteEngine On看起来像这样:

.htaccess

PS:我没有安装CI,所以我无法用CI测试这个,但我测试了这个并获得了增强的# forward all URLs starting with /admin/ to __anything.php RewriteRule ^(admin(?:/.*|))$ __anything.php?/$1 [L,NC] # set max_input_vars to 2000 for file __anything.php <FilesMatch "^__anything\.php"> php_value max_input_vars 20000 </FilesMatch> # your regular Codeignitor controller code RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L] 值。

答案 1 :(得分:1)

您可以使用以下内容,其中admin是您在Codeigniter中的控制器:

<FilesMatch "^(admin)">
    php_value max_input_vars 20000
</FilesMatch>

如果您想要定位多个CI控制器,可以使用管道将它们分开:

<FilesMatch "^(admin|another)">
    php_value max_input_vars 20000
</FilesMatch>

这可能不是你正在寻找的最佳方式,但它确实有效。我建议您使用需要在服务器配置或虚拟主机中设置的<Location><LocationMatch>(因为您无法在<Location>中使用<LocationMatch>.htaccess )。

一个例子是:

<Location /admin>
    php_value max_input_vars 20000
<Location>

答案 2 :(得分:1)

如果在启动管理控制器时尝试在php代码中设置硬编码值,该怎么办:

<?php
ini_set('max_input_vars', 2000);

如果服务器配置允许在运行时更改ini,则应该有效。