限制codeigniter中的url_suffix [英] Restrict the url_suffix in codeigniter
问题描述
我正在使用codeigniter 2.1.4,并且已设置 $ config ['url_suffix'] = .html;
I am using codeigniter 2.1.4 and I have set $config['url_suffix'] = ".html";
工作正常,没有任何麻烦。但是我发现,如果我使用 redirect();
函数将始终在目标网页网址上添加 url_suffix
。例如: site.com/login/success.html 。
It's working fine with out any trouble. But I found out that if I use redirect();
function will always add url_suffix
on the landing page url. eg: site.com/login/success.html.
我的问题还是要排除 url_suffix
同时使用 redirect()
函数?还是有在没有在codeigniter中设置 url_suffix
的情况下添加.html的方法,可能是.htaccess中的黑客?
My question is there anyway to exclude the url_suffix
while using the redirect()
function? or is there anyway to add .html without setting url_suffix
in codeigniter, may be some hack in .htaccess??
我尝试添加
RewriteEngine On
RewriteCond %{REQUEST_URI} !\.[a-zA-Z0-9]{3,4}
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ $1.html
在项目htaccess文件中,但是一旦我取消设置url_suffix变量,框架就会抛出404错误。可以解决吗?
in the project htaccess file, but once i unset the url_suffix variable the framework throws 404 error. Any work around?
谢谢:)
推荐答案
您可以离开 url_suffix
config空白 $ config ['url_suffix'] ='';
并定义特定的路由以添加 .html
后缀在某些情况下。
You could leave the url_suffix
config blank $config['url_suffix'] = '';
and define specific routes to add .html
suffix to some cases.
例如,对于博客文章:
在 routes.php
中(默认位于 application / config /
中) :
In routes.php
(which is located at application/config/
by default):
$route['blog/(.+)\.html'] = "posts/view_post/$1";
/* ^ ^ ^
| | |
Controller --- Method --- Post SEO url or ID
*/
这篇关于限制codeigniter中的url_suffix的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!