繁体   English   中英

从URL中删除index.php - Codeigniter 2

[英]Remove index.php From URL - Codeigniter 2

我无法从Codeigniter中的URL中删除index.php。 我用Codeigniter 1.7创建了一些网站,我使用的.htaccess代码在2中不起作用。

我试过用

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

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

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

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

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

</IfModule>

我也尝试过没有RewriteBase / in。

我已将$ config ['uri_protocol']更改为REQUEST_URI和QUERY_STRING而没有。

我设置了$ config ['index_page'] =“”;

文件结构是192.168.0.130/(site)/所以它必须返回到服务器的根目录,找不到index.php文件。

我所做的所有控制器都可以通过192.168.0.130/(site)/index.php/testcontroller来实现。

谢谢。

如果之前有人问过这个道歉 - 我已经看过并尝试过我能看到的东西。

编辑:

我还应该补充一点,我将默认文件夹更改为

应用

CI-2.0

的index.php

并将index.php中的路径更改为正确。

尝试使用您发布的第一个代码块,但不要使用/(dex)/index.php(obv替换(站点)与您的站点文件夹命名)。

这对我有用:

  1. 创建您的htaccess文件
  2. 将$ config ['index_page']设置为空(config.php)
  3. string Set $ config ['uri_protocol'] ='REQUEST_URI'; (config.php的)

这是我的htaccess文件:

Options -Indexes
Options +FollowSymLinks

RewriteEngine On
RewriteBase /

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,

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

#When your application folder isn't in the system folder

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

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php

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

# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin   

ErrorDocument 404 /index.php

资源:

http://taggedzi.com/articles/display/codeigniter-2-htaccess-and-friendly-urls

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

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

只需在根文件夹中将此添加到.htaccess即可

遵循其他人的所有说明以及此CodeIgnitor URL documnetation后 ,请不要忘记重新启动服务器 我只是忘记这样做,并继续尝试所有其他解决方案。

我在这2天了..尝试了一切可能。 我刚刚出来你需要以下内容:

类型:

sudo nano /etc/apache2/sites-available/default

并将AllowOverride None更改为AllowOverride All - 这将允许访问.htaccess文件

<Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
            # Uncomment this directive is you want to see apache2's
            # default start page (in /apache2-default) when you go to /
            #RedirectMatch ^/$ /apache2-default/
</Directory>

并且还在Apache上启用mod重写:

http://stackoverflow.com/questions/3131236/how-do-you-enable-mod-rewrite

希望这会有所帮助,马里奥

您只需在.htacess中添加以下代码即可。

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

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)在Application文件夹中编辑application / config / config.php文件

$config['base_url'] = 'http://localhost/projectName';

 $config['index_page'] = '';         // remove index.php 

我希望它对你有用

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM