Apache服务器在CI框架中配置伪静态
Apache服务器在CI框架中配置伪静态
1)打开Apache的重写模式,在apache的配置文件中找到:
LoadModule rewrite_module modules/mod_rewrite.so
去掉前面的#号
2)确定当前虚拟域名支持URL重写,在配置虚拟主机时有一项:
AllowOverride None
改为
AllowOverride All
3)在根目录下(index.PHP)同一级目录下建立一个.htaccess:
准备写正则移除 URL 中的 index.php,默认情况,你的 URL 中会包含 index.php 文件:
example.com/index.php/news/article/my_article
如果你的 Apache 服务器启用了 mod_rewrite ,你可以简单的通过一个 .htaccess 文件再加上
一些简单的规则就可以移除 index.php 了。
RewriteEngine on
#不显示index.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
4)在config/config.php/中修改URL后缀:
添加 URL 后缀($config['url_suffix'] = '.html';)
在你的 config/config.php 文件中你可以指定一个后缀,CodeIgniter 生成 URL 时会自动添
加上它。例如,一个像这样的 URL:
example.com/index.php/products/view/shoes
你可以添加一个后缀,如:.html ,这样页面看起来就是这个样子:
example.com/index.php/products/view/shoes.html
5)在config/routes.php中修改配置且添加正则匹配
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['welcome/lists_(:num)_(:num)'] = 'welcome/lists/$1/$2';
6)测试,例如:
public function lists($page,$search){
echo $page;
echo "</br>";
echo $search;
}
通过:http://localhost/two_exam/welcome/lists_13126726903_15135374298.html
案例效果如下:
13126726903
15135374298
http://www.vsnote.com/thinkphp-apache-rewrite.html
Apache服务器在CI框架中配置伪静态
1)打开Apache的重写模式,在apache的配置文件中找到:
LoadModule rewrite_module modules/mod_rewrite.so
去掉前面的#号
2)确定当前虚拟域名支持URL重写,在配置虚拟主机时有一项:
AllowOverride None
改为
AllowOverride All
3)在根目录下(index.PHP)同一级目录下建立一个.htaccess:
准备写正则移除 URL 中的 index.php,默认情况,你的 URL 中会包含 index.php 文件:
example.com/index.php/news/article/my_article
如果你的 Apache 服务器启用了 mod_rewrite ,你可以简单的通过一个 .htaccess 文件再加上
一些简单的规则就可以移除 index.php 了。
RewriteEngine on
#不显示index.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
4)在config/config.php/中修改URL后缀:
添加 URL 后缀($config['url_suffix'] = '.html';)
在你的 config/config.php 文件中你可以指定一个后缀,CodeIgniter 生成 URL 时会自动添
加上它。例如,一个像这样的 URL:
example.com/index.php/products/view/shoes
你可以添加一个后缀,如:.html ,这样页面看起来就是这个样子:
example.com/index.php/products/view/shoes.html
5)在config/routes.php中修改配置且添加正则匹配
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['welcome/lists_(:num)_(:num)'] = 'welcome/lists/$1/$2';
6)测试,例如:
public function lists($page,$search){
echo $page;
echo "</br>";
echo $search;
}
通过:http://localhost/two_exam/welcome/lists_13126726903_15135374298.html
案例效果如下:
13126726903
15135374298
http://www.vsnote.com/thinkphp-apache-rewrite.html