2

So I setted up the following lines in order to redirect some requests to my static domain:

RewriteEngine On
RewriteBase /

RewriteRule ^img/(.*)$ http://static.mydomain.com/img/$1 [R=301] 
RewriteRule ^css/(.*)$ http://static.mydomain.com/css/$1 [R=301]
RewriteRule ^js/(.*)$ http://static.mydomain.com/js/$1 [R=301,L]

But for some reason, when I link to a, let's say, a picture:

<img src="img/icons/hello.png">

It's showing 404 when it really exists on static server (which actually means it's not being redirected).

What am I doing wrong? I spent like two hours trying everything I know but no fix found.

Thank you very much in advance. Here is my full htaccess file:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteRule ^img/(.*)$ http://static.mydomain.com/img/$1 [R=301] 
    RewriteRule ^css/(.*)$ http://static.mydomain.com/css/$1 [R=301]
    RewriteRule ^js/(.*)$ http://static.mydomain.com/js/$1 [R=301,L]

    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule> 
WhatCoder
  • 33
  • 3
  • 1
    are you sure you have mod_rewrite enabled in your main httpd.conf? – Tudor Constantin May 30 '11 at 04:38
  • Obvious question: Is apache parsing your .htaccess file to begin with? AllowOverride set to all? – Jay Sidri May 30 '11 at 04:39
  • Yes, it's working for sure (rest of rules are working as expected). However, it's not redirecting to static! – WhatCoder May 30 '11 at 04:40
  • This is odd. My RewriteRules at working project looks almost the same: `RewriteRule ^pictures/(.*)$ http://i.staticdomain.ru/pictures/$1 [NC,L,R]`. Are you sure you specified `RewriteBase` correctly? `/` means your `img` URL would look like this: `http://yourdomain.com/img/someimage.jpg` – Nemoden May 30 '11 at 05:29

1 Answers1

1

One good way to debug the rewrites is to specify RewriteLog and RewriteLogLevel. You set log level up to 9 which logs quite a lot of things about the rewrites. Remember to disable the logging after debugging, because it is quite heavy for the apache process.

RewriteLog documentation

Eino
  • 99
  • 3