移除]; index.php文件"从URL - codeigniter [英] Remove "index.php" from URL - Codeigniter
问题描述
我已经看了去除codeigniter的文档中的的index.php
从URL访问不同的看法时,code演示了如何与Apache将其删除:
RewriteEngine叙述上
的RewriteCond $ 1 ^(指数\\ .PHP |图片|机器人\\ .txt)的!
重写规则^(。*)$ /index.php/$1 [L]
然而,当我去的http://本地主机/ code /家居
,我得到这样的:
所请求的网址/ code /家被此服务器上找到。
块引用>但访问
HTTP://localhost/$c$c/index.php/home
工作得很好,为什么它不是为我工作? p>我在Mac OS X Snow Leopard中使用
网站
目录:/用户/〜名为myusername〜/网站/ code
,和我没有使用任何软件,即MAMP,XAMPP。修改
对于
sudo的/ usr / sbin目录/ apachectl中-k重启-S
命令,我得到这样的:虚拟主机配置:
通配符NameVirtualHosts和_default_服务器:
*:80是了NameVirtualHost
默认的服务器code.local(/private/etc/apache2/httpd.conf:146)
80端口namevhost code.local(/private/etc/apache2/httpd.conf:146)
语法OK
解决方案您需要做的http://本地主机/ code您的Web根目录为code.local(在我的例子) 。
假设你在Mac OS X Snow Leopard中的设置是一样的我的。您应该添加以下行/etc/apache2/extra/httpd-vhosts.conf
<虚拟主机*:80>
的DocumentRoot/用户/〜名为myusername〜/网站/ code
服务器名称code.local
错误日志/私营/无功/日志/的Apache2 / code-的error_log
的CustomLog/私营/无功/日志/的Apache2 / code-访问日志共同
< /虚拟主机>另外,还要确保它在/etc/apache2/httpd.conf
注释掉#虚拟主机
包括/private/etc/apache2/extra/httpd-vhosts.conf然后添加code.local到看起来应该像这样你的/ etc / hosts文件
##
#主机数据库
#
#本地主机用于配置Loopback接口
#当系统启动。不要更改此项。
##
127.0.0.1本地主机
127.0.0.1 code.local然后重新启动Apache的/ usr / sbin目录/ apachectl中-k重启。
如果您不是超级用户,则可能需要须藤。
希望这有助于。编辑:
要检查您的虚拟主机的作品。运行此
sudo的/ usr / sbin目录/ apachectl中-k重启-S
要查看是否code.local已作为虚拟主机中的一个。然后尝试访问code.local / index.php文件/欢迎和code.local /欢迎来检查是否正常工作。
I've looked in the documentation of Codeigniter of removing the
index.php
from the URL when accessing different views, the code shows how to remove it with apache:RewriteEngine on RewriteCond $1 !^(index\.php|images|robots\.txt) RewriteRule ^(.*)$ /index.php/$1 [L]
However, when I go to
http://localhost/code/home
, I get this:The requested URL /code/home was not found on this server.
But accessing
http://localhost/code/index.php/home
works just fine, how come it isn't working for me?I'm on a Mac OS X Snow Leopard using the
Sites
directory:/Users/~myusername~/Sites/code
, and I'm not using any software, i.e. MAMP, XAMPP.EDIT
For the
sudo /usr/sbin/apachectl -k restart -S
command, I get this: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
解决方案You need to make "http://localhost/code" your web root as 'code.local' (in my example). Assuming that your setup on Mac OS X Snow Leopard is the same as mine.
You should add the following lines to "/etc/apache2/extra/httpd-vhosts.conf"
<VirtualHost *:80> DocumentRoot "/Users/~myusername~/Sites/code" ServerName "code.local" ErrorLog "/private/var/log/apache2/code-error_log" CustomLog "/private/var/log/apache2/code-access_log" common </VirtualHost>
Also make sure that it is uncommented in "/etc/apache2/httpd.conf"
# Virtual hosts Include /private/etc/apache2/extra/httpd-vhosts.conf
Then you add code.local to your "/etc/hosts" which should look like this
## # 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
Then restart your apache "/usr/sbin/apachectl -k restart".
You might need to sudo if you are not a super user. Hope this helps.
EDIT: To check if your virtual host works. Run this sudo /usr/sbin/apachectl -k restart -S To see if code.local has been added as one of your virtual hosts.
Then try accessing code.local/index.php/welcome and code.local/welcome to check if it works.
这篇关于移除]; index.php文件&QUOT;从URL - codeigniter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!