WhatCoder
WhatCoder

Reputation: 33

Htaccess for static content not working!

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> 

Upvotes: 2

Views: 758

Answers (1)

Eino
Eino

Reputation: 99

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

Upvotes: 1

Related Questions