我想从codeigniter网址中删除index.php 到目前为止,我尝试的当前配置为零结果
文件夹结构: XAMPP \ htdocs中\笨\应用\控制器\ OLX \ olx.php XAMPP \ htdocs中\笨\应用\视图\ OLX \ frmSignup
我的HTACCESS文件位置 xampp \ htdocs \ Codeigniter.HTACCESS,其中包含.HTACCESS文件中的以下内容
RewriteEngine On
RewriteBase /olx
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
使用phpinfo();
启用mod_rewrite对config.php文件进行了更改
$config['base_url'] = 'http://mypc/olx';
$config['index_page'] = '';
尝试访问此网址时
http://mypc/codeigniter/olx/frmSignup i get 404 error
对routes.php所做的更改
$route['default_controller'] = 'olx';
$route['olx/frmSignup'] = 'olx/frmSignup';
请帮助我想要在没有index.php的情况下访问我的应用。我正在使用Windows7
的localhost答案 0 :(得分:1)
在ubuntu的/etc/apache2/sites-available/000-default.conf中的虚拟主机文件中将AllowOverride None更改为AllowOverride All 在我的虚拟主机文件中将AllowOverride None更改为AllowOverride All,位于windows中的/etc/apache2/sites-available/default.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride All <---- replace None with All
</Directory>
<Directory /var/www >
Options Indexes FollowSymLinks MultiViews
AllowOverride All <--- replace None with All
Order allow,deny
allow from all
</Directory>
....
然后将此代码放在codeigniter
的根文件夹中的.htaccess文件中RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
它肯定会起作用。
答案 1 :(得分:0)
从http://ellislab.com/codeigniter%20/user-guide/general/urls.html - 尝试
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
答案 2 :(得分:0)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /Codeigniter
#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>
所以不是olx因为它是控制器而不是文件夹
配置中的
$config['base_url'] = '';
$config['index_page'] = '';
路线
$route['default_controller'] = "olx";
并移动你的 d:\ XAMPP \ htdocs中\笨\应用\控制器\ OLX \ olx.php 至 d:\ XAMPP \ htdocs中\笨\应用\控制器\ olx.php
和olx应该看起来像
class olx extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function index()
{
echo "test";
// or $this->load->view('olx/overview.php', $data);
}
}
并尝试localhost / codeigniter /或localhost / codeigniter / olx
答案 3 :(得分:0)
毕竟朋友说,你必须做另一件事(我想你是在localhost上做的):
首先,仔细检查建议: 然后转到Windows托盘,右键单击WAMP图标,然后单击它,转到Apache菜单,然后转到模块,然后检查rewrite_module以查看是否已选中,如果发现未选中则单击它(表示已禁用)启用它。现在再试一次并报告......
答案 4 :(得分:0)
您只需在根应用程序文件夹上创建.htaccess文件,或者如果已有,则进行编辑。以下.htaccess文件适用于我。
# BEGIN ci
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond ${REQUEST_URI} ^.+$
RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g|png|js|css|swf|php|ico|txt|pdf|xml)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>