我在使用 codeigniter 时遇到了一些问题,我有一个 .htaccess 来重写 index.php,如果我将我的项目放在 /var/www 上或者为其创建一个虚拟主机,它会很好地工作。
但我想使用我的用户目录,例如http://localhost/~userdir/myproject http://localhost/~userdir/myproject。如果我在尝试向控制器发出请求时使用我的用户目录,例如:http://localhost/~userdir/myproject/signup http://localhost/~userdir/myproject/signup我收到此错误:
未找到
在此服务器上找不到请求的 URL /index.php。
这是我当前的配置:
.htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|jquery|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L,QSA]
应用程序/配置/config.php
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
$config['encryption_key'] = 'myencryption_key';
//all remaining is the default config
这个配置非常适合http://本地主机/ http://localhost/以及具有类似域的生产环境http://example.com/ http://example.com/但不在我的用户目录中http://localhost/~userdir/project/ http://localhost/~userdir/project/
我做错了什么?有什么想法吗?
提前致谢。
好吧,我找到了一个解决方案代码点火器论坛 http://forum.codeigniter.com/thread-1016.html,首先我需要添加 RewriteBase 行,如下所示:
RewriteBase /~userdir/myproject/
然后,删除最后一行index.php 之前的斜杠。
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
有人这么说
RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|jquery|js|robots\.txt|favicon\.ico)
是多余的,下面两行代码覆盖它,
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
以及所有其他真实文件/目录。他们基本上说“如果请求不是针对真实文件,并且请求不是针对真实目录,则将请求传递给index.php。大概上面行中的所有内容都是真实文件或目录,因此不需要全部。
所以,我最终的 .htaccess 是这样的:
RewriteEngine on
RewriteBase /~userdir/myproject/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
它在本地运行良好http://localhost/~userdir/myproject http://localhost/~userdir/myproject也在生产中http://example.com/~userdir/myproject http://example.com/~userdir/myproject
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)