1

I've coded my website locally on the root of the server (WAMP running Apache 2.4.2) and i was setting the source for images and other resources with that in mind, so for instance an image called example.png would have "src=/img/example.png". Now i've moved the project to a subfolder, and the images won't load because their link is broken. I do not want to have to set the new source for each image on the html so i was hoping there would be another way to fix the links using mod_rewrite.

To demonstrate: I want a request for

http://localhost/img/logo.gif 

to go to

 http://localhost/newdir/img/logo.gif

Thanks in advance!

DaveQuinn
  • 189
  • 1
  • 6
  • 19

1 Answers1

2

This should do:

RewriteEngine on
RewriteRule !^newdir/ newdir%{REQUEST_URI}

See this post for more info regarding your problem:

https://stackoverflow.com/a/1612329/971459

Carefull to uncomment the following line in your httpd.conf file:

LoadModule rewrite_module modules/mod_rewrite.so

Having the following file structure:

-www
  -newfolder
     -img
        -header.png
  -.htaccess

When I access:

localhost/img/header.png I see the image

Community
  • 1
  • 1
Samson
  • 2,801
  • 7
  • 37
  • 55
  • Thank you radashk but it didn't work, i got an "Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request." – DaveQuinn Aug 18 '12 at 21:27
  • Here is the content of apache error log, i can't post the whole things due to website limitations but i think this is the problem [Sat Aug 18 22:30:30.683889 2012] [core:error] [pid 3076:tid 852] [client 127.0.0.1:54889] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace. – DaveQuinn Aug 18 '12 at 21:32
  • 1
    @PMMP: RewriteRule ^/img/(.*)$ /newdir/img/$1 [L] – InternetSeriousBusiness Aug 18 '12 at 21:35
  • The error went away but the pics still won't load "http://localhost/img/logo.gif 404 (Not Found) " The content of the .htacess is RewriteEngine on RewriteRule ^/img/(.*)$ /newdir/img/$1 [L] – DaveQuinn Aug 18 '12 at 21:39
  • What s the exact url you are trying to access? – Samson Aug 18 '12 at 21:43
  • I'm trying http://localhost/newdir/img/logo.gif but i get http://localhost/img/logo.gif – DaveQuinn Aug 18 '12 at 21:44
  • I really can't tell what's wrong.. did you mess up some settings? can you reinstall wamp? – Samson Aug 18 '12 at 22:12
  • Did you place the .htaccess file in the www directory? – Samson Aug 18 '12 at 22:12
  • It was on the subdirectory but now i've moved it to the root but it didn't solve the issue. – DaveQuinn Aug 18 '12 at 22:15