代码点火器 | .htaccess 从 url 中删除 index.php

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15350137/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 09:05:17  来源:igfitidea点击:

CodeIgniter | .htaccess removing index.php from url

php.htaccesscodeigniterrouting

提问by Sizzling Code

ok, i did exactly as asked in the documentation of codeigniter, created new file .htaccess

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

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

i am using xampp, so my url for accessing the site was

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

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

now after applying the above .htaccess file, i tried it without index.php like this

现在在应用上面的 .htaccess 文件后,我尝试了没有 index.php 这样的

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

but instead of working, it is redirecting me to this url

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

http://localhost:12/xampp

How to resolve this issue?

如何解决这个问题?

plus i am getting error on my page after trying the .htaccess

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

on top of page message is appearing,

出现在页面顶部的消息,

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


Edit:

编辑:

Here is some of my config.php file settings

这是我的一些 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;

采纳答案by DaneoShiga

Try defining the RewriteBase to /projects/zorkif_nextgen

尝试将 RewriteBase 定义为 /projects/zorkif_nextgen

RewriteBase /projects/zorkif_nextgen

回答by Mohamed Nagy

this is works well for me:

这对我来说很有效:

1- create .htaccess file in the root folder with the following content

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

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

2- from the config file change $config['index_page'] = 'index.php';to $config['index_page'] = '';

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

回答by kevin flynn

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

回答by AkisC

Try the following

尝试以下

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

回答by goenk

You can try this

你可以试试这个

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

For future reading This will help you Codeigniter remove index php from url using htaccess

供以后阅读 这将帮助您使用 htaccess 从 url 中删除索引 php

回答by Ricardo Lima

You may have look at config/routes.php.

您可能已经查看了 config/routes.php。

It may have been set to a default controller.

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

回答by landons

Don't use an .htaccess file to remove index.php from your URLs. This is an issue in your config. Look specifically at $config['base_url']and $config['index_page']

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