codeIgniter htaccess以及URL重写问题 [英] CodeIgniter htaccess and URL rewrite issues

查看:753
本文介绍了codeIgniter htaccess以及URL重写问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前从未使用codeIgniter,更不用说任何PHP框架,我想我会试试看。一切都正常,只是我似乎无法从URL中删除的index.php仍然能够访问我的网页。

I have never used CodeIgniter before, let alone ANY php framework and I thought I would give it a try. Everything is going fine except I cannot seem to remove the index.php from the URL and still access my pages.

我从来没有使用过的MVC架构,所以我学习,我走了,所以请原谅我,如果我这样做是错误的。

I have never used the MVC structure so I am learning as I go, so forgive me if I'm doing this wrong.

我想通过简单地键入本地主机/ CI /约,但目前我只能通过访问它的本地主机/ CI /访问视图我创建了名为about_page.php的index.php /约

I am trying to access a view I created called 'about_page.php' by simply typing in localhost/ci/about but currently I can only access it by using localhost/ci/index.php/about

该控制器的页面: /application/controllers/about.php
该模型的页面是: /application/models/about_model.php
而查看该网页是: /application/views/about_page.php

The controller for the page is: /application/controllers/about.php
The Model for the page is: /application/models/about_model.php
And the View for the page is: /application/views/about_page.php

我已经寻找解决这一问题,但一直没能找到一个。这里就是我已经搜查:

I have searched for a solution to this issue, but haven't been able to find one. Here is where I have already searched:

codeIgniter - 删除的index.php
<一href="http://stackoverflow.com/questions/11947234/$c$cigniter-how-to-remove-the-index-php-from-url">$c$cigniter - 如何从URL中删除的index.php
? <一href="http://www.farinspace.com/$c$cigniter-htaccess-file/">http://www.farinspace.com/$c$cigniter-htaccess-file/

CodeIgniter - removing index.php
Codeigniter - how to remove the index.php from url?
http://www.farinspace.com/codeigniter-htaccess-file/

codeIgniter自带的应用程序文件夹中的.htaccess文件只包含允许禁止从所有。所以,我创建在根目录下新建一个.htaccess文件,的http://localhost/ci/.htaccess 并添加这个code到它:

CodeIgniter comes with a .htaccess file in the 'application' folder which contains only Allow Deny From All. So I created a new .htaccess file in the root directory, http://localhost/ci/.htaccess and added this code to it:

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

在.htaccess文件是在根目录下,我得到一个500内部服务器错误。当我完全相同的文件复制到应用程序文件夹的500错误消失,但我仍然无法通过访问有关网页的本地主机/ CI /约

When the .htaccess file is in the root directory I get a 500 Internal Server Error. When I copy the exact same file into the applications folder the 500 error goes away, but I still cannot access the about page by using localhost/ci/about

我已经改变了 $配置['index_page'] ='的index.php'; $配置['index_page'] =' '; 键,我试图改变 $配置['uri_protocol'] ='自动'; $配置['uri_protocol '] ='REQUEST_URI'; ,但我仍然得到了内部服务器错误

I have already changed $config['index_page'] = 'index.php'; to $config['index_page'] = ''; AND I tried changing $config['uri_protocol'] = 'AUTO'; to $config['uri_protocol'] = 'REQUEST_URI'; but I am still getting the Internal Server Error.

我走进httpd.conf文件并注释掉了mod_rewrite.so模块,所以我知道mod_rewrite的是活动的。

I went into the httpd.conf file and uncommented the mod_rewrite.so module so I know mod_rewrite is active.

没有人有任何想法,为什么这不工作或我怎么能得到这个工作?我知道有很多关于这个问题的StackOverflow的问题,但我无法找到一个回答我的问题。

Does anyone have any ideas why this isn't working or how I can get this work? I know there are alot of questions on StackOverflow on this subject but I couldn't find one that answered my question.

我这样做对吗?应我甚至可以通过访问访问有关网页的本地主机/ CI /约或我必须在应用程序目录下创建一个关于目录?

Am I doing this right? Should I even be able to access the about page by visiting localhost/ci/about or do I have to create an 'about' directory in the 'application' directory?

推荐答案

有3个步骤删除的index.php

There are 3 steps to remove index.php

1.Make低于变化的应用程序/ config.php文件

1.Make below changes in application/config.php file

$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].'/Your Ci folder_name';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';

使用下面code在根目录下2.Make .htacces文件

2.Make .htacces file in your root directory using below code

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

3.Enable重写模式(如果不使你重写模式)

3.Enable rewrite mode (if your rewrite mode is not enabled)

我。首先,用下面的命令启动它:

i. First, initiate it with the following command:

a2enmod重写

二。编辑文件/ etc / apache2的/站点启用/ 000默认

ii. Edit the file /etc/apache2/sites-enabled/000-default

更改所有的设置AllowOverride无设置AllowOverride全部

三。用下面的命令重新启动服务器:

iii. Restart your server with the following command:

须藤/etc/init.d/apache2重启

这篇关于codeIgniter htaccess以及URL重写问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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