Apache 删除“;index.php“;来自URL-Codeigniter
我在Codeigniter的文档中查看了在访问不同视图时从URL中删除Apache 删除“;index.php“;来自URL-Codeigniter,apache,macos,codeigniter,osx-snow-leopard,Apache,Macos,Codeigniter,Osx Snow Leopard,我在Codeigniter的文档中查看了在访问不同视图时从URL中删除index.php,代码显示了如何使用apache删除它: RewriteEngine on RewriteCond $1 !^(index\.php|images|robots\.txt) RewriteRule ^(.*)$ /index.php/$1 [L] 但是,当我转到http://localhost/code/home,我明白了: VirtualHost configuration: wildcard NameV
index.php
,代码显示了如何使用apache删除它:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
但是,当我转到http://localhost/code/home
,我明白了:
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80 is a NameVirtualHost
default server code.local (/private/etc/apache2/httpd.conf:146)
port 80 namevhost code.local (/private/etc/apache2/httpd.conf:146)
Syntax OK
在此服务器上找不到请求的URL/code/home
但是访问http://localhost/code/index.php/home
工作正常,为什么对我不起作用
我在Mac OS X雪豹上使用站点
目录:/Users/~myusername~/Sites/code
,我没有使用任何软件,即MAMP、XAMPP
编辑
对于sudo/usr/sbin/apachectl-k restart-S
命令,我得到以下信息:
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80 is a NameVirtualHost
default server code.local (/private/etc/apache2/httpd.conf:146)
port 80 namevhost code.local (/private/etc/apache2/httpd.conf:146)
Syntax OK
所有uri部分都被重写,因此它指向/index.php/code/home。最好的方法是设置映射,例如指向您的/Users/~myusername~/Sites/code,然后您的所有请求都会在根级别上得到解决,一切都会正常工作 编辑:下层选民似乎是无知者,但无论如何 下面是您的代码现在的功能:
GET http://localhost/code/home
// rewritten to:
http://localhost/index.php/code/home
正如我之前所说的,好的方法是主机映射,这样您就可以在根级别上获取所有内容(这很好,因为您很可能会在生产服务上以这种方式获得这些内容…),这将实现我们在.htaccess中所做的更改
否则,您可以将Francesco的建议用于RewriteBase,但有一点改变:
// Francesco's RewriteRule does this:
http://localhost/code/home
// rewritten to"
http://localhost/code/index.php/code/home
因此,只需将重写规则更改为:
RewriteRule ^code/(.*)$ index.php?/$1 [L]
// rewrites in your case to:
http://localhost/code/index.php/home
// which is what you wanted, aye?
根据CodeIgniter文档中的文字 默认情况下,index.php文件将包含在URL中: 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请求都被视为对index.php文件的请求
你可以在这里找到它:试试这个
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?$1 [L,QSA]
我试了3次才找到一个可以用的你应该换
RewriteRule ^(.*)$ /index.php/$1 [L]
到
您还需要修改$config['index_page']变量,如下所示:
$config['index_page'] = '';
如果您愿意,请参阅我在的帖子。由于您的CI安装不在文档根目录中,您应该添加
RewriteBase/code/
,以使其正常工作
这是我用于CI安装的.htacces(这比官方文档中提供的要详细一些):
重新启动发动机
重写库/代码/
#删除用户对系统文件夹的访问权限。
#此外,这将允许您创建System.php控制器,
#以前这是不可能的。
#如果已重命名系统文件夹,则可以替换“系统”。
重写COND%{REQUEST_URI}^系统*
重写规则^(.*)$/index.php?/$1[L]
#当应用程序文件夹不在系统文件夹中时
#此代码段阻止用户访问应用程序文件夹
#提交人:Fabdrol
#将“应用程序”重命名为应用程序文件夹名称。
重写cond%{REQUEST_URI}^应用程序*
重写规则^(.*)$/index.php?/$1[L]
#检查用户是否试图访问有效文件,
#例如图像或css文档,如果这不是真的,它会发送
#请求index.php
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php?/$1[L]
#如果我们没有安装mod_rewrite,所有404
#可以发送到index.php,一切正常。
#提交人:ElliotHaughin
ErrorDocument 404/index.php
还要确保您的httpd可以处理.htaccess文件。如果在
元素中存在一行AllowOverride all
,请检查httpd.conf
希望这对你有帮助试试看
RewriteEngine on
RewriteBase /code/
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ code/index.php/$1 [L]
你需要做些什么?”http://localhost/code“您的web根目录为'code.local'(在我的示例中)。
假设您在Mac OS X Snow Leopard上的设置与我的相同
您应该在“/etc/apache2/extra/httpd vhosts.conf”中添加以下行
然后将code.local添加到“/etc/hosts”,如下所示
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
127.0.0.1 code.local
然后重新启动apache“/usr/sbin/apachectl-k restart”
如果您不是超级用户,您可能需要sudo。
希望这有帮助
编辑:
检查虚拟主机是否正常工作。运行这个
sudo/usr/sbin/apachectl-k restart-S
查看是否已将code.local添加为虚拟主机之一
然后尝试访问code.local/index.php/welcome和code.local/welcome以检查它是否有效。在
/etc/apache2/users/.conf
尝试添加
<Directory "/Users/<your user name>/Sites/">
Options Indexes MultiViews FollowSymlinks
AllowOverride all
Order allow,deny
Allow from all
</Directory>
选项索引多视图跟随符号链接
允许超越所有
命令允许,拒绝
通融
然后重新启动Apache以检查结果。在您的主codeigniter文件夹上复制.htaccess,我的文件夹是localhost/codeigniter/,然后将{RewriteBase/更改为RewriteBase/codeigniter/}
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
使用上述代码在codeigniter中web目录的根文件夹上创建.htacess文件。如果url链接包含index.php,您将能够删除index.php,这样它将显示页面而不会出错。或者,如果url不包含index.php,它将显示url中没有index.php的页面。要从url中删除index.php,只需添加
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
在.htaccess文件中,将.htaccess文件移到index.php位置附近
/var/www/CodeIgniter/index.php
/var/www/CodeIgniter/.htaccess
在config.php的config文件夹集中
$config['index_page'] = '';
我也有同样的问题,事情是这样的
签出此帖子。是的,它存储在那个目录中。需要“localhost/code”和“code.local”的输出吗?我猜你没有正确阅读我的文章,我已经在我的htaccess中包含了指南,但它不是wo
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
/var/www/CodeIgniter/index.php
/var/www/CodeIgniter/.htaccess
$config['index_page'] = '';