[英]CodeIgniter failed when the url does not end with the suffix .html
我是CodeIgniter的新手。 我在本地主机Eg中设置CI。 本地主机/ MyProjects下/笨/首页/指数
我的config.php中的url_config是这样的:
$config['url_suffix'] = ".html";
当我访问URL例如。
http://localhost/MyProjects/CodeIgniter/welcome/index
要么
http://localhost/MyProjects/CodeIgniter/welcome/index.html
页面已加载。
我的问题是,当URL不以.html结尾时,如何设置CodeIgniter失败?
所以,当我这样输入
http://localhost/MyProjects/CodeIgniter/welcome/index
请求将失败或重定向到禁止
尝试使用它来重定向它:
$this->load->helper('url');
if (preg_match("/.html/i", current_url())) {
echo "A match was found.";
} else {
// redirect(base_url());
show_404(); //if you want to show page not found
}
放在welcome.php
控制器中的function index()
中。
感谢您的解决方案,但我对您的解决方案进行了一些修改,例如:
if (preg_match("/.html/i", $_SERVER['REQUEST_URI'])) {
echo "A match was found.";
} else {
// redirect(base_url());
show_404(); //if you want to show page not found
}
因为如果我使用current_url()
函数,则CodeIgniter始终会提供已在$config['url_suffix']='.html';
设置的.html
扩展名$config['url_suffix']='.html';
所以我使用$_SERVER['REQUEST_URI']
因为它提供了地址栏中的实际内容。
感谢您的建议,我的问题已解决。 如果您来自印度尼西亚,makasih gan
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.