【问题标题】:problem with rewrite url codeigniter PHP htacess重写url codeigniter PHP htaccess的问题
【发布时间】:2019-12-06 20:52:20
【问题描述】:

我在 CodeIgniter 中重写时遇到问题。我开始学习 CI,但是 url 困扰着我。

http: //localhost/projetoci/index.php/restrict

我已经在 apache 中启用了重写模式。

LoadModule rewrite_module modules / mod_rewrite.so

我创建了 .htaccess 文件

RewriteEngine on
RewriteCond $ 1! ^ (Index \ .php | resources | robots \ .txt)
RewriteCond% {REQUEST_FILENAME}! -F
RewriteCond% {REQUEST_FILENAME}! -D
RewriteRule ^ (. *) $ Index.php / $ 1 [L, QSA]

但是这些都不能从 url 中删除 index.php。看了其他题目,没解决。

【问题讨论】:

标签: php codeigniter url-rewriting


【解决方案1】:

application/config文件夹中,找到并替换config.php文件中的以下代码。

$config['index_page'] = "";

现在设置 .htaccess 文件如下。

<IfModule mod_rewrite.c>

    RewriteEngine On

    RewriteBase /projetoci/

    #This bit rewrites your host name to include www    
    #RewriteCond %{HTTP_HOST} !^(www\.|$) [NC]  
    #RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    #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 ^(.*)$ /projetoci/index.php?/$1 [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /projetoci/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 ^(.*)$ /projetoci/index.php?/$1 [L]

</IfModule>

【讨论】:

  • $config['index_page'] = '';我将您的代码用于 htacess,但如果我尝试“localhost/projetoci/restrict”,请转到“localhost/dashboard”xampp 页面
  • 请检查配置文件夹中的 routes.php 文件。可能是你那里有 url 路由。也请检查 config.php 文件$config['uri_protocol'] = 'REQUEST_URI';
  • $route['default_controller'] = 'home'; $route['404_override'] = ''; $route['translate_uri_dashes'] = 假; $route['restrict'] = 'restrict'; $config['uri_protocol'] = 'REQUEST_URI';我只有“home”和“restrict”分隔在 2 个“控制器”中 public function index(){ $this->template->show("login.php"); }
  • 请勾选其中的“限制”控制器和索引功能。是否有任何“重定向”代码到仪表板视图?
  • 所以在“login.php”文件中,它可能会重定向到仪表板。因为可能存在您已经登录的情况,您将被重定向到仪表板页面。
猜你喜欢
  • 2013-01-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多