codeIgniter的index.php用的.htaccess删除 [英] CodeIgniter Remove index.php with .htaccess

查看:142
本文介绍了codeIgniter的index.php用的.htaccess删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've been working on this for an hour already so I figured I might as well ask.

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

I am trying to remove the index.php from my CodeIgniter app's URL and can not do it.

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

The app is running on a dedicated server in my office and I access the app through the url http://smr_local

这是我的基本虚拟主机块

This is my base virtual host block

<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文件

Here is my .htaccess file

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';

现在,当我试图访问我的基地网址的http:// smr_local /用户/课程我得到了我的Apache的错误日志中的错误我得到这个。

Right now when I'm trying to access my base url http://smr_local/user/courses I get an error in my apache error log I get this.

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

我真的不知道下一个尝试的东西。任何帮助将是AP preciated。

I really don't know what to try next. Any help would be appreciated.

推荐答案

你检查官员的用户指南

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

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

You can easily remove this file by using a .htaccess file with some simple rules. Here is an example of such a file, using the "negative" method in which everything is redirected except the specified items:

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

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

In the above example, any HTTP request other than those for index.php, images, and robots.txt is treated as a request for your index.php file.

我一直在与codeigniter previously,这就是我如何得到它的工作:

I have been working with Codeigniter previously and that is how I get it to work:

下面是我的的.htaccess (假设你已经默认文件夹结构):

Here is my .htaccess (assuming you have default folder structure):

<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的配置。


If this won't help, your problem likely in Apache configuration.

然后提供的httpd.conf 和其他相关的配置,不仅虚拟主机

Then provide your httpd.conf and any other relevant configurations, not only virtual-hosts.

这篇关于codeIgniter的index.php用的.htaccess删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆