【发布时间】:2013-08-26 07:29:14
【问题描述】:
我知道这个问题更适合服务器故障,但不幸的是,我因为质量差的问题而被禁止(我在我提出的 2-3 个问题上被否决。)所以问这些问题的下一个最佳地点是这里。
我有两个与 CodeIgniter 路由相关的问题。
第一个问题是我似乎无法摆脱网址中的index.php。我关注了instructions on how to remove it。我的 WAMP 服务器根目录下的 .htaccess 文件(见下文)中有以下 mod 重写代码(CI 位于根目录,而不是在其自己的文件夹中)。我在httpd.conf 文件LoadModule rewrite_module modules/mod_rewrite.so 中取消了对这一行的注释。我从$config['index_page'] = "index.php"; 中删除了index.php。我重新启动了所有 WAMP 服务。
我的第二个问题是我有一个名为search 的控制器和一个名为index 的方法。我想将生成的 URL 从 http://localhost/index.php/search/index 更改为 http://localhost/search/whatever_im_searching_for。我在 routes.php 文件中尝试了以下自定义路由,但没有成功:$route['search/(.*)'] = "search/$1";
RewriteEngine On
# Put your installation directory here:
# If your URL is www.example.com/, use /
# If your URL is www.example.com/site_folder/, use /site_folder/
RewriteBase /
# Do not enable rewriting for files or directories that exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# For reuests that are not actual files or directories,
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]
我很难理解.htaccess 中的代码以及如何使用 CI 的自定义路由。任何帮助将不胜感激。提前谢谢你。
编辑 1
【问题讨论】:
标签: php .htaccess codeigniter wampserver