用笨的.htaccess删除的index.php(CodeIgniter Remove index.

2019-08-03 13:24发布

我一直工作在这一个小时了,所以我想我还不如问。

我想从我的CodeIgniter应用程序的URL中删除index.php文件并不能做到这一点。

应用程序是在我的办公室在专用服务器上运行,我通过URL访问应用程序http://smr_local

这是我的基本虚拟主机块

<VirtualHost 192.168.1.90:80> 
    ServerAdmin admin@server.com
    DocumentRoot "/var/www/smr.dev/app"
    ServerName smr_local
    ErrorLog "/etc/httpd/logs/error_log"
    CustomLog "/etc/httpd/logs/access_log" common
    <Directory /var/www/smr.dev/app>
        Order allow,deny
        Allow from all
        AllowOverride All
    </Directory>
    <IfModule mod_rewrite.c>
        RewriteEngine on
    </IfModule>
</VirtualHost>

这里是我的.htaccess文件

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

而我的配置文件

$config['base_url']    = "http://smr_local/";
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

现在,当我试图访问我的基本URL http://smr_local/user/courses我得到一个错误在我的Apache错误日志中我得到这个。

File does not exist: /var/www/smr.dev/app/user

我真的不知道下一个尝试的东西。 任何帮助,将不胜感激。

Answer 1:

你检查的官方用户指南 ?

example.com/index.php/news/article/my_article

您可以轻松地通过使用.htaccess文件有一些简单的规则删除此文件。 下面是一个使用中,一切都被重定向除指定项的“负”的方法这样的文件的一个例子,:

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

在上面的例子中,比那些的index.php,图像和其他的robots.txt任何HTTP请求被视为对您的index.php文件的请求。


我一直在与笨以前,这就是我如何得到它的工作:

这是我.htaccess (假设你的默认文件夹结构):

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # Removes access to the system folder by users.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    # Prevents user access to the application 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]
</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule> 

这是有关部分config.php

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

如果这不会帮助,您的问题可能在Apache配置。

然后提供您的httpd.conf和其他相关的配置,不仅virtual-hosts



文章来源: CodeIgniter Remove index.php with .htaccess