我在 CI 中找到了很多 URL 重写的示例,但不是最终的好的解决方案,我有这样的 url
www.somesite.com/index.php/tehnicki/tekstovi
我想要这样的网址
www.somesite.com/about.html
这个关于是GET变量,在MySql查询中,它不会是数字,而是一些NAME,如何做到这一点?
我必须在 tehnicki Controller 中编写才能获取 GET 变量,CI 中是否有用于 MySQL 攻击的帮助程序,或者我必须自己编写:)
最佳答案
好吧,让我们看看,看起来很困惑而且没有意义,但我会给你你需要的东西。
首先我们必须删除index.php文件: - 使用它作为.htaccess
//.htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|Skin|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
接下来,在 config.php 中将 index_page 设置为空字符串
// application/config/config.php
$config['index_page'] = '';
在同一个文件上,滚动到 url_suffix,并将其设置为 .html
// application/config/config.php
$config['url_suffix'] = '.html';
现在前往你的routes.php并应用重写规则
// application/config/routes.php
$route['about'] = "tehnicki/tekstovi";
我将快速解释我在这里做了什么,以便您了解它是如何工作的: 1-我们删除了网址的index.php部分以清理它 2-我们添加了一个将在所有页面上生成的 url 后缀 3-我们应用了一个重写规则,将/about.html 与 Controller tehnicki 和操作 tekstovi (tehnicki/tekskovi) 相匹配
关于mysql - CodeIgniter URL 重写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17031729/