【问题标题】:Rename URL in Codeigniter在 Codeigniter 中重命名 URL
【发布时间】:2014-08-14 09:50:36
【问题描述】:

我想从我的 Codeigniter 和 Bonfire 项目 URL 中删除 /public/index.php..

我当前的网址:http://localhost/public/index.php/page 所需网址:http://localhost/page

但我希望链接、图像和机器人的路径完好无损!如何做到这一点?使用 .htaccess 有什么好的资源吗?

【问题讨论】:

  • 先尝试阅读文档/谷歌,然后告诉你你做了什么?
  • 我不太懂apache语言
  • 要删除public 文件夹,您可以使用vhost,要删除index.php,您可以阅读文档。 Codeigniter 是一个很好的框架,因为它完善了文档。

标签: php .htaccess codeigniter bonfire


【解决方案1】:

我认为你必须采取以下步骤:

  1. 将您的 .htaccess 文件从应用程序转移到根目录

  2. 删除/注释旧文件中的旧代码(使用#)并粘贴到下面的代码

重写引擎开启 #RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php?/$0 [PT,L] RewriteRule ^/?ajax/(.*)$ ajax.php?$1 [NC,QSA,L]

  1. 根据 $config['index_page'] 从配置文件中删除 index.php,如下所示 $config['index_page'] = '';

  2. 然后从 Apache

    激活重写模块

它应该适合你。

【讨论】:

  • hmmm 这工作正常,但现在我必须更改我所有页面上的每个链接并排除 public/index.php 以任何方式解决这个问题?
  • 好吧,我不知道你要改变多少个链接,我想你必须改变它们。但为了以后,你可以将关键链接作为常量存储在config目录下的constant.php中,并且可以在每个源文件中使用该常量。
  • 你介意再解释一件事,最后一个 RewriteRule 是什么?关于ajax,我发现没有它一切正常
  • 好吧,我很抱歉,但我对 .htaccess 语言了解不多,但我根据下面的链接更改了代码。这可能会帮助你stackoverflow.com/questions/8664480/…
【解决方案2】:

尝试阅读CodeIgniter URLs,“删除 index.php 文件”小节:

在.htaccess中

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

在 config.php 中:

$config['index_page'] = '';

【讨论】:

  • 我没有帮助,因为我还需要删除 public/ 位更不用说保持链接完好无损
【解决方案3】:

你可以试试这个吗?

RewriteEngine On

RewriteBase /



#Removes access to the system folder by users.

#Additionally this will allow you to create a System.php controller,

#previously this would not have been possible.

#'system' can be replaced if you have renamed your system folder.

RewriteCond %{REQUEST_URI} ^system.*

RewriteRule ^(.*)$ /index.php/$1 [L]



#Checks to see if the user is attempting to access a valid file,

#such as an image or css document, if this isn't true it sends the

#request to index.php

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php/$1 [L]

这对我来说很好用

【讨论】:

【解决方案4】:

您将我认为的应用程序中的 .htaccess 文件复制到您的 basedir 中。

或者为您的 basedir 添加一个新的 .htaccess。

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

【讨论】:

  • 是的,我也阅读了 Codeigniter 手册,但这不起作用
猜你喜欢
  • 1970-01-01
  • 2018-11-04
  • 1970-01-01
  • 2020-09-12
  • 1970-01-01
  • 2016-08-18
  • 2011-09-23
  • 1970-01-01
相关资源
最近更新 更多