删除“index.php"来自 URL - Codeigniter [英] Remove "index.php" from URL - Codeigniter
问题描述
我查看了 Codeigniter 的文档,在访问不同视图时从 URL 中删除了 index.php
,代码显示了如何使用 apache 删除它:
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]
但是,当我转到 http://localhost/code/home
时,我得到了:
However, when I go to http://localhost/code/home
, I get this:
在此服务器上找不到请求的 URL/code/home.
The requested URL /code/home was not found on this server.
但是访问 http://localhost/code/index.php/home
工作正常,为什么它不适合我?
But accessing http://localhost/code/index.php/home
works just fine, how come it isn't working for me?
我在 Mac OS X Snow Leopard 上使用 Sites
目录:/Users/~myusername~/Sites/code
,我没有使用任何软件,即MAMP、XAMPP.
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.
编辑
对于 sudo/usr/sbin/apachectl -k restart -S
命令,我得到这个:
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
推荐答案
您需要将http://localhost/code"设置为code.local"(在我的示例中).假设您在 Mac OS X Snow Leopard 上的设置与我的相同.
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.
您应该将以下行添加到/etc/apache2/extra/httpd-vhosts.conf"
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>
还要确保在/etc/apache2/httpd.conf"中取消注释
Also make sure that it is uncommented in "/etc/apache2/httpd.conf"
# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf
然后将 code.local 添加到/etc/hosts"中,它应该如下所示
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
然后重启你的 apache "/usr/sbin/apachectl -k restart".
Then restart your apache "/usr/sbin/apachectl -k restart".
如果您不是超级用户,则可能需要 sudo.希望这会有所帮助.
You might need to sudo if you are not a super user. Hope this helps.
检查您的虚拟主机是否工作.运行这个须藤/usr/sbin/apachectl -k 重启 -S查看 code.local 是否已添加为您的虚拟主机之一.
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.
然后尝试访问 code.local/index.php/welcome 和 code.local/welcome 以检查它是否有效.
Then try accessing code.local/index.php/welcome and code.local/welcome to check if it works.
这篇关于删除“index.php"来自 URL - Codeigniter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!