codeIgniter的.htaccess index.php文件重写不工作的用户目录 [英] CodeIgniter .htaccess index.php rewrite not working on user directory

查看:282
本文介绍了codeIgniter的.htaccess index.php文件重写不工作的用户目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小问题,codeigniter,我有一个的.htaccess的重写它的伟大工程,如果我把我的项目上的/ var / WWW或者如果我做一个虚拟主机吧。

不过,我想用我的用户目录,例如的http://本地主机/〜用户目录/ myproject的。如果我用我的用户目录时,我试图做的请求,如控制器:的http://本地主机/〜用户目录/ MyProject的/注册我得到这个错误:

  

未找到

     

所请求的URL的index.php在此服务器上找到。

这是我目前的配置:

的.htaccess

  RewriteEngine叙述上
的RewriteCond $ l ^(指数\ .PHP |(*)\瑞士法郎。|论坛|图片| CSS |下载| jquery的| JS |机器人\ .TXT |图标\ .ICO)!
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(。*)$ /index.php?/$1 [L,QSA]
 

的application / config / config.php文件

  $配置['BASE_URL'] ='';
$配置['index_page'] ='';
$配置['uri_protocol'] ='自动';
$配置['encryption_key'] ='myencryption_key';
//所有剩下的是默认的配置
 

此配置的伟大工程在的http://本地主机/ ,也对生产enviroments与像的 http://example.com/ 但不能在我的用户目录下的的http://本地主机/〜用户目录/项目/

我做错了吗?有什么想法吗? 先谢谢了。

解决方案

嗯,我发现的 codeigniter论坛的,首先我需要补充的RewriteBase线如下:

 的RewriteBase /〜用户目录/ MyProject的/
 

然后,index.php文件上最后一行之前删除斜杠。

 重写规则^(。*)$的index.php?/ $ 1 [L,QSA]
 

有人说,

 的RewriteCond $ l ^(指数\ .PHP |!。(*)\ SWF |论坛|图片| CSS |下载| jquery的| JS |机器人\ .TXT | favico ñ\ .ICO)
 

是多余的,下面两行code覆盖它,

 的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
 

  

和其他真正的文件/目录。他们基本上是说如果请求不是一个真实的文件,并且请求不是一个真正的目录,将请求传递给index.php文件。presumably一切从上面的线是一个真正的文件或目录,所以它的没有必要的。

所以,我最后的.htaccess是这样的:

  RewriteEngine叙述上
的RewriteBase /〜用户目录/ MyProject的/
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(。*)$的index.php?/ $ 1 [L,QSA]
 

它的工作原理以及本地与的http://本地主机/〜用户目录/ myproject的还生产与<一个HREF =htt​​p://example.com/~userdir/myproject相对=nofollow> http://example.com/~userdir/myproject

I have a little problem with codeigniter, I have a .htaccess for rewrite the index.php it works great if I put my projects on /var/www or if I make a virtual host for it.

But I want to use my user directory such as http://localhost/~userdir/myproject. If I use my user directory when I'm trying to do request to a controller like: http://localhost/~userdir/myproject/signup I get this error:

Not Found

The requested URL /index.php was not found on this server.

This is my current configuration:

.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]

application/config/config.php

$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
$config['encryption_key'] = 'myencryption_key';
//all remaining is the default config

This config works great on http://localhost/ and also on production enviroments with a domain like http://example.com/ but not on my user directory http://localhost/~userdir/project/

What I doing wrong? Any thoughts? Thanks in advance.

解决方案

Well, I found a solution in codeigniter forums, first I need to add RewriteBase line as follows:

RewriteBase /~userdir/myproject/

Then, remove the slash before index.php on last line.

RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

Someone said that

RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|jquery|js|robots\.txt|favico​​n\.ico)

is redundant, the following two lines of code cover it,

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

and all other real files/directories. They basically say "if the request is not for a REAL file, and the request is not for a REAL directory, pass the request to index.php. Presumably everything from the above line is a real file or directory, so it's not needed at all.

So, my final .htaccess is like this:

RewriteEngine on
RewriteBase /~userdir/myproject/   
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

It works well locally with http://localhost/~userdir/myproject also on production with http://example.com/~userdir/myproject

这篇关于codeIgniter的.htaccess index.php文件重写不工作的用户目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆