从URL中移除笨的index.php主机服务器上(remove index.php from the

2019-11-02 08:32发布

大家好我尝试隐藏URL中的index.php,以及类似的东西:

我想:mydomain.com/index.php/mycontroler

是这样的:mydomain.com/mycontroler

这里是我的.htaccess

Options -Multiviews
Options +FollowSymLinks

RewriteEngine On

RewriteBase /

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond $1 !^(index\.php|images|robots\.txt|css)

RewriteRule ^(.*)$ index.php?/$1 [L] 

这里是我的conf.php

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

问题是,这是工作中的好地方,但不是在服务器

这里是我的文件配置

- bin
- etc
- mail
- public_ftp
- public_html
 -- application
 -- assets
 -- system
 -- .htaccess
 -- index.php

帮助家伙

Answer 1:

$config['base_url']    = 'http://'.$_SERVER['HTTP_HOST'].'/';
 $config['index_page'] = '';

htaccess的:

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

如果仍然得到麻烦尝试改变:

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

或somenthing不同的多个(在config.php中,你会发现所有可用的尝试为uri_protocol PARAM的选项)



Answer 2:

这里的.htaccess的东西,

<IfModule mod_rewrite.c>

    Options +FollowSymLinks -Indexes
    RewriteEngine on

    # NOTICE: If you get a 404 play with combinations of the following commented out lines
    #AllowOverride All
    #RewriteBase /

    # Restrict your site to only one domain
    #RewriteCond %{HTTP_HOST} !^www\.
    #RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    <IfModule mod_php5.c>
        RewriteRule ^(.*)$ index.php/$1 [L]
    </IfModule>

    <IfModule !mod_php5.c>
        RewriteRule ^(.*)$ index.php?/$1 [L]
    </IfModule>

</IfModule>

#prevent access to htaccess file
<Files .htaccess>
 order allow,deny
 deny from all
</Files>

#disable directory browsing
Options All -Indexes
IndexIgnore *

而在config.php

  1. 设置基本URL像“ http://www.example.com/ ”
  2. $配置[“index_page”]设置为空
  3. 串设置$配置[ 'uri_protocol'] = 'REQUEST_URI'


Answer 3:

我所有的.htaccess

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

你应该确保该属性AllowOverride设置正确,如: AllowOverride ALL在你httpd.conf目录段



Answer 4:

使根.htaccess文件下面的变化

 RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

它为我工作。



文章来源: remove index.php from the url in Codeigniter on host server