gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 01:02:59 25 4
gpt4 key购买 nike

我知道这个问题更适合服务器故障,但不幸的是,我因质量低劣的问题而被禁止(我对我提出的 2-3 个问题投了反对票。)所以下一个提出这些问题的最佳地点是这里。

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

第一个问题是我似乎无法摆脱 url 中的 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 的 Controller 和一个名为 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

enter image description here

最佳答案

像这样编辑你的 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>

要在 url 中包含您的搜索词,您可以查看以下内容:

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

关于php - 无法删除 index.php,自定义路由不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18399558/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com