Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ignore .jpg, .gif etc files in .htaccess files with mod_rewrite?

Status
Not open for further replies.
Basically, if someone access a .gif file, it won't try and process it as a rewrite rule - it will simply show it "as is"

ATM, my rewrite rules are over-lapping with the images etc, thus I'm getting dead images :(

TIA

Andy
 
Wicked, so just after the Rewriteengine On line, or before each line? (we have about 30 different rewrites)

TIA

Andy
 
Hi

httpd.apache.org said:
One or more [tt]RewriteCond[/tt] can precede a [tt]RewriteRule[/tt] directive. The following rule is then only used if both the current state of the URI matches its pattern, and if these conditions are met.
So the [tt]RewriteCond[/tt] has effect on the first [tt]RewriteRule[/tt] which follows it.

Are you sure you need all 30 [tt]RewriteRule[/tt]s ?

Feherke.
 
Hi,

Guess I could probably trim it down a bit now - with the "ignore" bit in place. This is what it currently looks like:

Code:
RewriteEngine On

#RewriteRule images/(.*) /var/[URL unfurl="true"]www/html/blogs/images/$1[/URL] [L]
#RewriteRule static/(.*) /var/[URL unfurl="true"]www/html/blogs/static/$1[/URL] [L]

RewriteRule (.*).js /var/[URL unfurl="true"]www/html/blogs/$1[/URL] [L]


RewriteRule ^$ /cgi-bin/blogs/page.cgi?g=index.html [L]
RewriteRule ^/$ /cgi-bin/blogs/page.cgi?g=index.html [L]
RewriteRule ^index.html$ /cgi-bin/blogs/page.cgi?g=index.html [L]

# CSS/images/other page type rewrites, so they get shown, instead of page.cgi picking them up
RewriteRule (.*)\.css $1.css [L]
RewriteRule (.*)\.php $1.php [L]
RewriteRule (.*)\.zip $1.zip [L]
RewriteRule ^images/(.*) images/$1 [L]

# stuff so you can call custom templates via yoursite.com/g-template_name.html
RewriteRule ^g-(.*).html? /cgi-bin/blogs/page.cgi?p=$1 [L]
RewriteRule ^g-(.*)/? /cgi-bin/blogs/page.cgi?p=$1 [L] 


# detailed pages rewrite
RewriteRule Detailed/(.*)\.html$ /cgi-bin/blogs/page.cgi?g=Detailed/$1.html [L]
RewriteRule ^.*L([0-9]+)/(.*)\.html$ /cgi-bin/blogs/page.cgi?g=Detailed/$1.html [L]
RewriteRule ^.*L([0-9]+)/?$ /cgi-bin/blogs/page.cgi?g=Detailed/$1.html [L]

# New, Pop, Ratings etc rewrite rules

RewriteRule ^New/?$ /cgi-bin/blogs/page.cgi?g=New [L]
RewriteRule ^Ratings/?$ /cgi-bin/blogs/page.cgi?g=Ratings [L]
RewriteRule ^Cool/?$ /cgi-bin/blogs/page.cgi?g=Cool [L]


# event rewrite stuff
RewriteRule ^events/?$ /cgi-bin/blogs/events.cgi [L]
RewriteRule ^events/(.*)/(.*)/([0-9]+).html$ /cgi-bin/blogs/events.cgi?ID=$3&action=view [L]
RewriteRule ^events/(.*)/(.*).html$ /cgi-bin/blogs/events.cgi?state=$1&city=$2 [L]
RewriteRule ^events/(.*).html$ /cgi-bin/blogs/events.cgi?state=$1 [L]

# category page rewrite
RewriteRule ^(.*)/index\.html$ /cgi-bin/blogs/page.cgi?g=$1/index.html [L]

# more page rewrite rule
RewriteRule ^(.*)/more([0-9]+)\.html$ /cgi-bin/blogs/page.cgi?g=$1/more$2.html [L]

I'll do some testing, but I think well over half of those could be got rid of =)

Cheers

Andy
 
Now the img/js file stuff is resolvecd - the rewrite rules were condenced to just:

Code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !\.(jpg|gif|js)$
RewriteRule ^g-(.*).html? /cgi-bin/blogs/page.cgi?p=$1 [L]

RewriteCond %{REQUEST_FILENAME} !\.(jpg|gif|js)$
RewriteRule ^g-(.*)/? /cgi-bin/blogs/page.cgi?p=$1 [L] 

RewriteCond %{REQUEST_FILENAME} !\.(jpg|gif|js)$
RewriteRule ^(.*)$ /cgi-bin/blogs/page.cgi?g=$1 [L]

Thanks =)

Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top