微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法删除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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐