[英]Codeigniter - client posted links with capital letters in URL
我的客户以大写字母打印了指向该站点的链接。 我有一个CI安装程序,需要更改htaccess或基本控制器(我正在尝试在mo上使用许多选项)来像这些示例一样工作(用户在其地址栏中键入此内容):
http://www.site.com/HAPPY/chappy- > http://www.site.com/happy/chappy
http://www.SITE.com/HaPpy/CHAPpy- > http://www.site.com/happy/chappy
http://WWW.Site.CoM/happy/chappY- > http://www.site.com/happy/chappy
依此类推...我似乎无法让htaccess仅仅说“将所有内容都放入,将其转换为小写然后进行处理”。
这甚至有可能..?
是的,您可以在输入文本后立即将输入转换为小写字母。 您可以使用javascript。 请参考下面的代码片段。
function makeLowercase() {
document.form1.outstring.value = document.form1.instring.value.toLowerCase();
}
<input name="outstring" type="text" value="" size="30" onkeyup="makeLowercase();" onblur="makeLowercase();">
或者,您可以在PHP中使用strtolower()函数将数据秘密转换为小写字母并进行处理。
您可以使用.htaccess改写主机名之后的部分(无论如何,该部分不区分大小写):
http://www.chrisabernethy.com/force-lower-case-urls-with-mod_rewrite/
用您自己的show_error
函数扩展CI_Exceptions核心类 。 使用show_error
的原始代码,但按照以下show_error
开头添加快速检查:
class MY_Exceptions extends CI_Exceptions {
/**
* General Error Page
*
* This function takes an error message as input
* (either as a string or an array) and displays
* it using the specified template.
*
* @access private
* @param string the heading
* @param string the message
* @param string the template name
* @return string
*/
function show_error($heading, $message, $template = 'error_general', $status_code = 500)
{
// First try forwarding to all-lowercase URL if there were caps in the request
if ($_SERVER['REQUEST_URI'] != strtolower($_SERVER['REQUEST_URI']))
{
header('Location: ' . strtolower($_SERVER['REQUEST_URI']));
return;
}
/* Rest of original function to follow... */
根据需要进行自定义,请记住您可能希望大写的URI的其他部分。
您也可以使用pre_system(或pre_controller)挂钩实现类似的功能,尽管我个人仅在已将挂钩用于其他用途的情况下才这样做。
您可以将核心路由库扩展为不区分大小写。 那就是您放置strtolower()
函数的地方。
将其添加到404错误处理程序是一个坏主意。
如果要使用LMK作为源,则应该扩展库,复制1函数并添加strtolower()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.