【问题标题】:CodeIgniter | .htaccess removing index.php from url代码点火器 | .htaccess 从 url 中删除 index.php
【发布时间】:2013-02-27 07:28:27
【问题描述】:

好的,我完全按照codeigniter文档中的要求做了,创建了新文件.htaccess

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

我使用的是xampp,所以我访问该网站的网址是

http://localhost:12/projects/zorkif_nextgen/index.php/main

现在在应用上述 .htaccess 文件后,我在没有 index.php 的情况下尝试过这样的

http://localhost:12/projects/zorkif_nextgen/main

但它没有工作,而是将我重定向到这个网址

http://localhost:12/xampp

如何解决这个问题?

另外,在尝试 .htaccess 后我的页面上出现错误

出现在页面顶部的消息,

 Error Occured.
Warning!. Make sure you perform the correct action.
The Action has been completed Successfully. 

编辑:

这是我的一些 config.php 文件设置

$config['base_url'] = '';
$config['index_page'] = 'index.php';
$config['uri_protocol'] = 'AUTO';
$config['url_suffix'] = '';
$config['enable_hooks'] = FALSE;
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
$config['allow_get_array']      = TRUE;
$config['enable_query_strings'] = FALSE;
$config['controller_trigger']   = 'c';
$config['function_trigger']     = 'm';
$config['directory_trigger']    = 'd'; // experimental not currently in use
$config['sess_cookie_name']     = 'zk_ci_session';
$config['sess_expiration']      = 7200;
$config['sess_expire_on_close'] = TRUE;
$config['sess_encrypt_cookie']  = TRUE;
$config['sess_use_database']    = TRUE;
$config['sess_table_name']      = 'sys_ci_sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update']  = 300;
$config['csrf_protection'] = TRUE;
$config['csrf_token_name'] = 'csrf_test_name';
$config['csrf_cookie_name'] = 'csrf_cookie_name';
$config['csrf_expire'] = 7200;
$config['rewrite_short_tags'] = FALSE;

【问题讨论】:

标签: php .htaccess codeigniter routing


【解决方案1】:

这对我很有效:

1-在根文件夹中创建.htaccess文件,内容如下

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

2- 从配置文件中将$config['index_page'] = 'index.php'; 更改为$config['index_page'] = '';

【讨论】:

    【解决方案2】:

    尝试将 RewriteBase 定义为 /projects/zorkif_nextgen

    RewriteBase /projects/zorkif_nextgen
    

    【讨论】:

    • 非常好。谢谢你。是的,它现在正按我的意愿工作 :)
    【解决方案3】:

    试试下面的

    RewriteEngine on
    RewriteBase /
    # Hide the application and system directories by redirecting the request to index.php
    RewriteRule ^(application|system|\.svn) index.php/$1 [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [QSA,L]
    

    【讨论】:

    • 谢谢你的回复,我试过你的代码,它可以工作,但它是一样的,我必须编写 index.php 才能让它工作。如果我尝试 zorkif_nextgen/main 然后它再次将我重定向到 localhost:12/xampp??为什么它会将我重定向到主根目录。?
    • 我已经尝试了其中的 10 个。你是为我的 xampp 工作的人。
    【解决方案4】:
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR] 
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]
    

    【讨论】:

      【解决方案5】:

      你可以试试这个

      <IfModule mod_rewrite.c> 
         RewriteEngine on 
         RewriteCond $1 !^(index\.php|images|swf|uploads|js|css|robots\.txt) 
         RewriteRule ^(.*)$ /ci/index.php/$1 [L] 
      </IfModule>
      

      供以后阅读这将对您有所帮助Codeigniter remove index php from url using htaccess

      【讨论】:

        【解决方案6】:

        你可能看过 config/routes.php。

        它可能已设置为默认控制器。

        【讨论】:

          【解决方案7】:

          不要使用 .htaccess 文件从您的 URL 中删除 index.php。这是您的配置中的一个问题。具体看$config['base_url']$config['index_page']

          【讨论】:

          • 你能告诉我如何在没有 htaccess 的情况下从 url 中删除 index.php 吗?
          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2014-01-15
          • 2021-09-25
          • 1970-01-01
          • 2011-05-20
          • 2017-03-15
          • 1970-01-01
          相关资源
          最近更新 更多