Mod_rewrite and URL redirection - APACHE,Mod_rewrite,PHP,Codeigniter

你。 提交于 2020-01-06 17:46:27

问题


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.

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

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

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>

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/

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

http://mysite.local/mysite/mysite

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 .

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

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

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 Log:

 [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/

回答1:


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>

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




回答2:


It looks like this line is messing with you:

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

Try this instead

RewriteCond %{REQUEST_URI}  !^(index\.php|images|lists|eshots|useruploads|temp|SpryAssets|css|js|robots\.txt|timthumb\.php)



回答3:


you need to enable rewrite module for apache.. you can do this by going to wamp tray icon > apache > apache module then select rewrite module.



来源:https://stackoverflow.com/questions/13537003/mod-rewrite-and-url-redirection-apache-mod-rewrite-php-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!