编程语言
首页 > 编程语言> > 无法删除index.php,自定义路由不起作用

无法删除index.php,自定义路由不起作用

作者:互联网

我知道这个问题更适合于服务器故障,但是不幸的是,我被禁止回答质量低下的问题(我对提出的2-3个问题投了反对票.)因此,提问这些问题的下一个最佳场所是这里.

我有两个与CodeIgniter路由有关的问题.

第一个问题是我似乎无法摆脱url中的index.php.我遵循的是instructions on how to remove it.我的WAMP服务器根目录(.CI位于根目录,而不是其自己的文件夹)中的.htaccess文件(如下所示)中具有以下mod重写代码.我已经在httpd.conf文件LoadModule rewrite_module modules / mod_rewrite.so中取消注释此行.我从$config [‘index_page’] =“ index.php”;中删除了index.php.然后我重新启动了所有WAMP服务.

我的第二个问题是我有一个称为搜索的控制器和一个称为索引的方法.我想将结果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

解决方法:

像这样编辑您的htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$index.php?/$1 [L]

RewriteCond %{REQUEST_URI} ^LoginTut.*
RewriteRule ^(.*)$index.php?/$1 [L]

RewriteCond $1 !^(index\.php|images|table-images|js|robots\.txt|css|captcha)

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$index.php?$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
 ErrorDocument 404 index.php
</IfModule>

要在网址中包含搜索字词,可以查看以下内容:

https://stackoverflow.com/a/12070284/1379394

标签:wampserver,codeigniter,php,htaccess
来源: https://codeday.me/bug/20191030/1968412.html