【问题标题】:is there any way to remove index.php file from url有什么方法可以从 url 中删除 index.php 文件
【发布时间】:2014-05-20 16:33:51
【问题描述】:

我正在尝试从我的 htaccess 文件的 URL 内容中删除“index.php”

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

working URL
localhost/qasim/outlets/index.php/items_controller/

Error on
localhost/qasim/outlets/items_controller/

有什么办法可以摆脱 index.php :)

我的 config.php 文件内容文件如下:

    <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');


$config['base_url'] = '';


$config['index_page'] = '';


$config['uri_protocol'] = 'REQUEST_URI';

$config['url_suffix'] = '';


$config['language'] = 'english';


$config['charset'] = 'UTF-8';


$config['enable_hooks'] = FALSE;



$config['subclass_prefix'] = 'MY_';


$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['log_threshold'] = 0;

$config['log_path'] = '';

$config['log_date_format'] = 'Y-m-d H:i:s';

$config['cache_path'] = '';


$config['encryption_key'] = 'abc';


$config['sess_cookie_name']     = 'ci_session';
$config['sess_expiration']      = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie']  = FALSE;
$config['sess_use_database']    = FALSE;
$config['sess_table_name']      = 'ci_sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update']  = 300;


$config['cookie_prefix']    = "";
$config['cookie_domain']    = "";
$config['cookie_path']      = "/";
$config['cookie_secure']    = FALSE;

$config['global_xss_filtering'] = FALSE;


$config['csrf_protection'] = FALSE;
$config['csrf_token_name'] = 'csrf_test_name';
$config['csrf_cookie_name'] = 'csrf_cookie_name';
$config['csrf_expire'] = 7200;


$config['compress_output'] = FALSE;


$config['time_reference'] = 'local';


/
$config['rewrite_short_tags'] = FALSE;


$config['proxy_ips'] = '';

经过所有更改,我的配置文件现在看起来像它,但它不起作用

【问题讨论】:

  • 您是通过 localhost 而不是域访问它。这可能是重写时的问题。请告诉我您的操作系统和网络服务器是哪个?
  • 我正在使用 win7、xampp 和我正在使用的框架是 codeigniter。
  • 不工作是否有任何其他设置与 xampp 相关,因为我是第一次玩 .htaccess?
  • Oohhhhhhhhhh 谢谢它完成了我的 .htaccess 文件放在了问题所在的应用程序文件夹中。 :)

标签: php codeigniter


【解决方案1】:

在 config.php 中添加以下替换

$config['index_page'] = "index.php"$config['index_page'] = ""

替换 $config['uri_protocol'] ="AUTO"$config['uri_protocol'] = "REQUEST_URI"

在 .htaccess 中

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

在 XAMPP 中的域下编辑托管站点

编辑C:\Windows\System32\drivers\etc\hosts(将该文件拖放到记事本) 在文件末尾添加这一行 127.0.0.1 www.test.com

编辑Fullpath\XAMPP\apache\conf\extra\httpd-vhosts.conf

在最后添加这些代码

NameVirtualHost *:80 <VirtualHost *:80> DocumentRoot "Fullpath/xampp/htdocs/Projectname" ServerName test.com ServerAlias www.test.com </VirtualHost>

确保将完整路径替换为您的确切路径。重启 apache 重启浏览器并输入 www.test.com

您可以查看您的项目,然后检查重写。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-07
    • 2013-08-09
    • 2012-12-27
    相关资源
    最近更新 更多