重写Codeigniter URL以删除index.php [英] Codeigniter URL rewrite to remove index.php
问题描述
首先,我尝试了此处指定的建议:
First of all, i have tried the suggestion specified in here:
- CodeIgniter删除index.php无效
- codeignitor:删除index.php不起作用
- CodeIgniter .htaccess index.php重写不起作用在用户目录上
- 如何删除"index.php"在codeigniter的路径中
- https://ellislab.com/expressionengine/user-guide /urls/remove_index.php.html
- CodeIgniter的Rewriterule无法正常工作
- CodeIgniter removing index.php not working
- codeignitor: Remove index.php not working
- CodeIgniter .htaccess index.php rewrite not working on user directory
- How to remove "index.php" in codeigniter's path
- https://ellislab.com/expressionengine/user-guide/urls/remove_index.php.html
- Rewriterule for CodeIgniter not working
我正在尝试删除地址栏上臭名昭著的index.php
.
I am trying to remove the infamous index.php
on the address bar.
这是我当前的配置:
在我的/etc/apache2/sites-available/my.website.com.conf文件中,我这样输入:
In my /etc/apache2/sites-available/my.website.com.conf file i put this:
<Directory /path/to/root/directory/>
AllowOverride All
Order allow,deny
Allow from all
</Directory>
在我的/etc/apache2/apache2.conf文件中,我输入以下内容:
In my /etc/apache2/apache2.conf file, i put this:
<Directory /path/to/root>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
在我的codeigniter根目录(与index.php相同的目录)中,我有一个.htaccess像这样:
In my codeigniter root directory (same dir with index.php), i have a .htaccess like this:
<IfModule mod_rewrite>
RewriteEngine On
RewriteBase /
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
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>
# 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
</ifmodule>
最后,我的application/config/config.php:
And finally, my application/config/config.php:
$config['base_url'] = 'http://my.website.com';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
当我在本地PC(运行Ubuntu 14.04)上测试上述配置时,它工作正常.但是,当我尝试在服务器(运行Ubuntu 14.04)上复制配置时,某种程度上它不起作用.
When i tested the above config on my local PC (running Ubuntu 14.04) it works just fine. However when i try to replicate the config on my server (running Ubuntu 14.04), somehow it does not work.
这样做:
- http://my.website.com/<<显示默认的Codeigniter欢迎页面
- http://my.website.com/ << Shows default Codeigniter welcome page
http://my.website.com/controller_name/ << Shows :
未找到 在此服务器上找不到请求的URL/登录. 位于my.website.com端口80的Apache/2.4.7(Ubuntu)服务器
Not Found The requested URL /login was not found on this server. Apache/2.4.7 (Ubuntu) Server at my.website.com Port 80
http://my.website.com/index.php/controller_name <<会显示该页面,但是由于打印以下内容,无法正确获取静态文件的网址(即JS/CSS/图像):
http://my.website.com/index.php/controller_name << shows the page, however URL to static files (i.e JS/CSS/images) are not properly fetched, since printing this:
<link rel="stylesheet" href="assets/styles/material-design-icons.css" type="text/css" />
<link rel="stylesheet" href="assets/styles/font.css" type="text/css" />
<link rel="stylesheet" href="assets/styles/app.css" type="text/css" />
将附加 index.php .
我在这里想念什么吗?有人可以指出我正确的方向吗?
Am i missing something here? Can someone point me to the right direction?
谢谢.
编辑#1 下面是我的文件夹结构
EDIT #1 Below is my folder structure
编辑#2 我可以确认已启用mod_rewrite
EDIT #2 I can confirm that mod_rewrite is enabled
推荐答案
好的,您提到了很多与您的问题相关的Stack链接.
OK, You mentioned lot of Stack links which related to your question.
更改此设置
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
并将其添加到.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
注意:在localhost
index.php
中的某些时间不会删除.
Note: Some time in localhost
index.php
will not removed.
并包括您的css/js/images
CSS:
<link rel="stylesheet" href="<?php echo base_url()?>assets/styles/material-design-icons.css" type="text/css" />
JS:<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/in/easing.js"></script>
图:<img src="<?php echo base_url()?>assets/image/logo.jpg" alt=""/>
CSS:
<link rel="stylesheet" href="<?php echo base_url()?>assets/styles/material-design-icons.css" type="text/css" />
JS :<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/in/easing.js"></script>
Img:<img src="<?php echo base_url()?>assets/image/logo.jpg" alt=""/>
文件结构应该是
- application
- assets
- style
- material-design-icons.css
- font.css
- app.css
- js
- easing.js
- image
- logo.jpg
- index.php
- .htaccess(Post in my code)
编辑01
在config/routes.php
$route['default_controller'] = "";//give default controller name
$route['404_override'] = '';
这篇关于重写Codeigniter URL以删除index.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!