【问题标题】:Codeigniter htaccess and base_urlCodeigniter htaccess 和 base_url
【发布时间】:2012-03-01 08:18:10
【问题描述】:

我安装了codeigniter并开始在上面写一些代码。首先我想删除index.php并对其进行一些研究。我用下面的一个小htaccess代码删除它,

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

然后将config.php中的base_url设置为,

$config['base_url'] = 'http://localhost/pasaj/'; 

然后我决定在表单的操作中使用 base_url

就这么写了(请看动作)

  <form method="post" id="formSubmit" name="fSubmit" action=<?php base_url(); ?>"kayit/kayitOnay/">

但是没有用

并像这样打印网址

我所做的一切都不起作用

我怀疑是从我的 htaccess 文件中删除的。我用它来删除 codeigniter 默认中的 index.php。

并设置我的新 这样的基本网址必然

http://localhost/pasaj/index.php/

不要更改表单代码上方的任何内容

它有效。

现在,我想仍然使用这个 htaccess 文件来删除 index.php,但是当 htaccess 文件存在时,我的 base_url 工作错误。 htaccess 文件可能有什么变化?

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:

    试试这个

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

    我在本地服务器上的 htaccess 文件如下所示:

    对于 Zend 框架网络:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]
    

    对于 CodeIgniter 网络:

    RewriteEngine on
    RewriteBase /pasaj/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
    RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization},L]
    

    【讨论】:

    • 在我的回答中添加了另一个例子,还是不行?
    【解决方案2】:

    这是我的标准 htaccess 文件。

    <IfModule mod_rewrite.c>
        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]
    
        #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 ^(.*)$ /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]
    </IfModule>
    
    <IfModule !mod_rewrite.c>
        # If we don't have mod_rewrite installed, all 404's
        # can be sent to index.php, and everything works as normal.
        # Submitted by: ElliotHaughin
    
        ErrorDocument 404 /index.php
    </IfModule>
    

    您可能需要更改重写基础。

    【讨论】:

      【解决方案3】:

      要从 url 中删除 index.php,您可以尝试以下操作。

      Open config.php from system/application/config directory and replace
      $config['index_page'] = “index.php” by $config['index_page'] = “”
      
      Create a “.htaccess” file in the root of CodeIgniter directory and add the following lines.
      
      RewriteEngine on
      RewriteCond $1 !^(index\.php|resources|robots\.txt)
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ index.php/$1 [L,QSA]
      
      In some case the default setting for uri_protocol does not work properly. To solve this problem just replace
      $config['uri_protocol'] = “AUTO” by $config['uri_protocol'] = “REQUEST_URI” from system/application/config/config.php
      

      【讨论】:

      • 如果可能的话你能解释一下这个链接吗...RewriteRule ^(.*)$ index.php/$1 [L,QSA]
      猜你喜欢
      • 1970-01-01
      • 2017-02-09
      • 2018-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-26
      • 2016-02-19
      • 1970-01-01
      相关资源
      最近更新 更多