Codeigniter 2.0友好URL不用在Mac OS X Snow Leopard上
-
03-10-2019 - |
题
由于某种原因,在CI 2.0中,URL不起作用。
http://localhost/myapp/ - will open the default controller (bc it finds index.php)
http://localhost/myapp/index.php/home/ - will open the default controller
http://localhost/myapp/home/ - will show path not found
我不确定这是2.0的问题,还是我的配置的特定问题。
我正在Mac OS X Snow Leopard上运行Apache 2。
我寻找.htaccess解决方案,但找不到CI 2.0的任何解决方案。
解决方案 2
真正的问题是,在Snow Leopard中,实际目录配置通常位于/private/etc/apache2/httpd.conf中,现在位于/private/etc/apache2/users/ [username.conf by default clossymlinks中,basteroverride bastersymlinks被禁用在那里,即使在常规httpd.conf中启用了它,也必须手动修复它
棘手。谢谢大家。否则,您所需要的只是人们已经指出的常规.htaccess。
其他提示
您是否有Apache中的重写规则来处理这样的代码字母?看: http://codeigniter.com/wiki/mod_rewrite/
- 默认情况下第一个将起作用(默认为index.php)
- 秒会因为您将其传递给index.php而起作用
- 第三条不会没有重写规则。
.htaccess
CodeIgniter 1.7的解决方案也将适用于CodeIgniter 2.0。 .htaccess
用于配置独立于CodeIgniter的Apache Web服务器。
(来自 CodeIgniter手册 因此应该正常工作。)
$ sudo sudo chgrp staff /Library/WebServer/Documents/
$ sudo chmod 775 /Library/WebServer/Documents/
之后,我所有的应用都将在文件夹/库/WebServer/Documents/Documents/
喜欢“测试”
/Library/Web服务器/文档/测试
$ echo "Hello World" >> /Library/WebServer/Documents/testing/index.php
http://localhost/testing
==> it should appear Hello World
现在,在文件夹'/library/web服务器/文档/'下,您将放置CI文件夹,您必须添加
.htaccess
RewriteEngine On
RewriteCond $1 !^(index\.php)
RewriteRule ^(.+)$ index.php?$1 [L]
AddHandler php5-script .php
在您的ci_folder/application/config.php上
$config['index_page'] = '';
我认为仅此而已!享受!
你可以找到它 这里。它以下是“删除index.php文件”标头。
删除index.php文件
默认情况下,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文件的请求。
最好的方法是安装XAMPP,与我一起工作。
只需停止本地Apache,然后将您的应用程序放入HTDOC(XAMPP)。
您将看到您的应用程序遵守友好的URL。
祝你好运