使用.htaccess删除index.php不能处理codeigniter hostgator

时间:2015-07-28 07:15:10

标签: .htaccess codeigniter

基本上我想在我的网址中删除index.php。

我认为我的.htaccess没有在Hostgator上工作,我已经在这些.htaccess,codeigniter和hostgator上搜索了我的问题。

这是我在hostgator中的文件夹结构

  

/ cgi-bin
/ httpdocs
  | --- /申请
  | --- / system
  | ---。htaccess
  | --- index.php

我的.htaccess

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

我的config.php

$config['base_url'] = 'www.example.com'; // this is only an example because our website is confidential
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
  

编辑:抱歉是白痴。在我发布此问题后,我联系了Hostgator,并尝试以下答案。他们说我是   在Windows server而不是Apache server上投放,因此我的.htaccess会   不行,所以我需要将其转换为web.config。对不起,那些   浪费时间回答这个问题。谢谢

     

编辑:我认为@Deep Parekh的答案是正确的,因为@David说它运作正常

5 个答案:

答案 0 :(得分:1)

通常我在Hostgator上使用这个htaccess:

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

确保您更改了config.php文件:

$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';

答案 1 :(得分:0)

我认为可以使用htaccess。 http://support.hostgator.com/articles/specialized-help/technical/apache-htaccess/how-to-edit-your-htaccess-file

也许尝试这些htaccess。它适用于我当地的项目。

    DirectoryIndex index.php
    RewriteEngine on

    RewriteCond %{REQUEST_URI} !^(index\.php|\.swf|forums|images|css|downloads|js|robots\.txt|favicon\.ico)$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*) ./index.php [L]

答案 2 :(得分:0)

.htaccess会看:

<IfModule mod_rewrite.c>
  RewriteEngine On
  #RewriteBase /

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^ index.php [QSA,L]



# Removes trailing slashes (prevents SEO duplicate content issues)
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.+)/$ $1 [L,R=301]
</IfModule>

在codeiginator配置中:

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

如果htaccess无效,那么

  1. 配置Apache mod_rewrite

    a2enmod重写

  2. 将以下代码添加到/ etc / apache2 / sites-available / default

    AllowOverride All

答案 3 :(得分:0)

config/config.php

$config['base_url'] = '';
$config['index_page'] = '';

在.htacess中

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L] 
</IfModule

答案 4 :(得分:0)

这对我有用:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
相关问题