[英]CodeIgniter Remove index.php with .htaccess
我已经为此工作了一个小时,所以我想问一下。
我正在尝试从我的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
我真的不知道下一步该怎么做。 任何帮助,将不胜感激。
您是否查看了官方用户指南 ?
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,images和robots.txt的HTTP请求以外的任何HTTP请求都被视为对index.php文件的请求。
我以前一直在使用Codeigniter,这就是我如何使其工作的方式:
这是我的.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
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.