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:

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]

ErrorDocument 404 index.php

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

标签:wampserver,codeigniter,php,htaccess

来源: https://codeday.me/bug/20191030/1968412.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值