Redirect by filetype

Using mod_rewrite to handle various content issues

Redirect by filetype

Postby Rokster » Sun Feb 25, 2007 10:07 pm

Hi there all,

My directory structure looks as follows :

webroot
| - assets
| | - css
| | - images
| | - scripts
| - app

The current .htaccess file reads as follows


Code: Select all
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /iFleetIII/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule>


I need to redirect all requests for stylesheets to /webroot/assets/css, images ( lets say .png|jpg|gif ) to /webroot/images and javascript to /webroot/scripts.

I'm a complete noob at this.. spent the whole day getting my head twisted. Can someone please help !?!?

Thanks !
~Rok

*edit spelling errors
Rokster
 
Posts: 2
Joined: Sun Feb 25, 2007 9:54 pm

Postby richardk » Tue Feb 27, 2007 9:23 am

Try
Code: Select all
Options +FollowSymLinks

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteRule ^(.+\.css)$ /assets/css/$1 [NC,L]
    RewriteRule ^(.+\.js)$ /assets/scripts/$1 [NC,L]
    RewriteRule ^(.+\.(jpe?g|png|bmp|gif))$ /assets/images/$1 [NC,L]

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

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule>
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Rokster » Wed Mar 07, 2007 5:32 pm

Richard,

Thanks for your suggestion.. however it loops !! Anyone / any ideas on how to fix that ?

Basically it runs in circles until I get the
Code: Select all
mod_rewrite: maximum number of internal redirects reached. Assuming configuration error. Use 'RewriteOptions MaxRedirects' to increase the limit

message.

Thanks !
Rokster
Rokster
 
Posts: 2
Joined: Sun Feb 25, 2007 9:54 pm

Postby richardk » Sat Mar 10, 2007 9:17 am

Add
Code: Select all
RewriteRule ^assets(/.*)?$ - [L]

after
Code: Select all
RewriteEngine On
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Content

Who is online

Users browsing this forum: No registered users and 10 guests

cron