Mod_rewrite和URL重定向-APACHE,Mod_rewrite,PHP,Codeigniter [英] Mod_rewrite and URL redirection - APACHE,Mod_rewrite,PHP,Codeigniter

查看:105
本文介绍了Mod_rewrite和URL重定向-APACHE,Mod_rewrite,PHP,Codeigniter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常具体的问题.我正在使用wamp服务器在本地运行我的codeigniter项目.我已经加载了mod_rewrite,它显示在我的phpinfo中.

I have got a very specific problem. I am using wamp server to run my codeigniter projects locally. I have loaded mod_rewrite in and it is showing in my phpinfo.

在我的wamp根目录中,有一个codeigniter项目文件夹"mysite".这是mysite的目录结构.

In my wamp root directory, I have a codeigniter project folder "mysite".Here is the directory structure of mysite.

-mysite
   |--images
   |--eshots
   |--useruploads
   |--temp
   |--SpryAssets
   |--css
   |--js
   |--timthumb

启用此mod_rewrite后,我在Windows目录中修改了我的主机"文件,并在虚拟主机文件中添加了以下代码行,以便以这种方式访问​​我的网站. (mysite.local)

After enabling this mod_rewrite, I modified my "host" file in my windows directory and added this line of code in my virtual host file to access my website like this. (mysite.local)

   127.0.0.1 mysite.local

此后,我在根目录(即mysite文件夹下)中创建了htaccess文件

After this I created an htaccess file in root directory (i.e under mysite folder)

  htaccess file:

  RewriteEngine on

  RewriteCond $1  !^(index\.php|images|lists|eshots|useruploads|temp|SpryAssets|css|js|robots\.txt|timthumb\.php)

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

  <IfModule mod_security.c>

  SecFilterEngine Off

  SecFilterScanPOST Off

  </IfModule>

此后,当我尝试从沼泽中访问我的网站时,它无处可寻.例如,如果我从本地主机的项目文件夹(即mysite)中单击,它将带我回到本地主机文件夹,并且我的URL如下所示:

After this, when I try to access my website from the wamp, it leads me to nowhere. For example, if I click from localhost's project folder i.e mysite, it takes me back to the localhost folder and my URL looks like this:

http://mysite.local/mysite/

,当我再次单击mysite时,它会显示如下网址:

and when I click on mysite again, it shows the URL like this:

http://mysite.local/mysite/mysite

在此之后,我的链接不会将我带到网页.并留在这里. 为什么我会从服务器得到这种行为? CODEIGNITER或htaccess文件是否有任何问题阻止了此操作?我需要采取哪些步骤,才能使每个N正常工作,包括javascript,css,images.

And after this, my link doesn't take me to the web pages. And remain stuck here. Why am I getting this behavior from server? Is there any problem with CODEIGNITER or htaccess file that is stopping this? And what steps I need to do so that I could get each N everything working including javascript, css, images .

如何处理这个具有挑战性的问题?
通常,人们说您需要启用mod_rewrite或阅读Apache提供的手册.

How to deal with this challenging problem?
Mostly people say you need to have your mod_rewrite enabled or read manual provided from Apache.

[更新]: 当我尝试WID新的codeigniter project.FIRST时,我将htaccess文件以外的所有文件都复制到了项目文件夹中.幸运的是,我能够导航到索引页面,但没有显示任何CSS,图像,脚本. 我的htaccess只包含以下这些位:.上的RewriteEngine.

[UPDATED]: when I TRIED WID new codeigniter project.FIRST,I copied all the files apart from htaccess file into project folder.Luckily i was able to navigate to the index page but it didnt show me any css,image,scripts. My htaccess consists of only these bits: RewriteEngine on .

现在我该怎么做才能使我的js,图像按上述方式工作?Apache_error日志如下所示:.此外,当我尝试移至下一页时,它显示((Error:404))所请求的URL/Code/wham.local/categories/listings/Products找不到."建议.wham.local是虚拟主机.

What shall i do now to make my js,images work as above?Apache_error log looks like this:.Also,when i try to move onto next pages ,it says "(Error:404)The requested URL /Code/wham.local/categories/listings/Products was not found".Kindly suggest.Where wham.local is virtual host.

apache_error日志:

 [Sun Nov 25 13:00:54 2012] [error] [client 127.0.0.1] File does not exist: D:/wamp/www/css, referer: http://localhost/Code/
 [Sun Nov 25 13:00:54 2012] [error] [client 127.0.0.1] File does not exist: D:/wamp/www/css, referer: http://localhost/Code/
 [Sun Nov 25 13:00:54 2012] [error] [client 127.0.0.1] File does not exist: D:/wamp/www/js, referer: http://localhost/Code/
 [Sun Nov 25 13:00:54 2012] [error] [client 127.0.0.1] File does not exist: D:/wamp/www/js, referer: http://localhost/Code/
 [Sun Nov 25 13:00:54 2012] [error] [client 127.0.0.1] File does not exist: D:/wamp/www/js, referer: http://localhost/Code/
 [Sun Nov 25 13:00:54 2012] [error] [client 127.0.0.1] File does not exist: D:/wamp/www/js, referer: http://localhost/Code/

 [Sun Nov 25 13:00:54 2012] [error] [client 127.0.0.1] File does not exist: D:/wamp/www/js, referer: http://localhost/Code/

 [Sun Nov 25 13:00:54 2012] [error] [client 127.0.0.1] File does not exist: D:/wamp/www/images, referer: http://localhost/Code/
 [Sun Nov 25 13:00:54 2012] [error] [client 127.0.0.1] File does not exist: D:/wamp/www/images, referer: http://localhost/Code/
 [Sun Nov 25 13:00:54 2012] [error] [client 127.0.0.1] File does not exist: D:/wamp/www/images, referer: http://localhost/Code/
 [Sun Nov 25 13:00:54 2012] [error] [client 127.0.0.1] File does not exist: D:/wamp/www/images, referer: http://localhost/Code/
 [Sun Nov 25 13:00:54 2012] [error] [client 127.0.0.1] File does not exist: D:/wamp/www/images, referer: http://localhost/Code/
 [Sun Nov 25 13:00:54 2012] [error] [client 127.0.0.1] File does not exist: D:/wamp/www/images, referer: http://localhost/Code/
 [Sun Nov 25 13:00:54 2012] [error] [client 127.0.0.1] File does not exist: D:/wamp/www/images
 [Sun Nov 25 13:01:03 2012] [error] [client 127.0.0.1] File does not exist: D:/wamp/www/images
 [Sun Nov 25 13:01:55 2012] [error] [client 127.0.0.1] File does not exist: D:/wamp/www/images
 [Sun Nov 25 13:01:56 2012] [error] [client 127.0.0.1] File does not exist: D:/wamp/www/Code/wham.local, referer: http://localhost/Code/

推荐答案

检查C:\ wamp \ bin \ apache \ Apache2.2.17 \ conf中的http.conf文件 如果他们是这样的条目 #虚拟主机 #include conf/extra/httpd-vhosts.conf 然后打开文件httpd-vhosts.conf,在其中添加以下行.

check the http.conf file in C:\wamp\bin\apache\Apache2.2.17\conf if their is entry like this #Virtual hosts #Include conf/extra/httpd-vhosts.conf then open the file httpd-vhosts.conf add below lines in it.

     <VirtualHost *:80>
       DocumentRoot  "C:/wamp/www/mysite/"
       ServerName     mysite.local
      </VirtualHost>

     <VirtualHost *:80>
      DocumentRoot  "C:/wamp/www/"
      ServerName     localhost
      </VirtualHost>

否则,您也可以将此行添加到httpd.conf文件中 并重新启动您的服务器. 这是虚拟主机的概念.

otherwise you can add this line to httpd.conf file also and restart ur server. this is the virtual host concept.

这篇关于Mod_rewrite和URL重定向-APACHE,Mod_rewrite,PHP,Codeigniter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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