The image size limit has been raised to 1mb! Anything larger than that should be linked to. This is a HARD limit, please do not abuse it.
Our new Indie Games subforum is now open for business in G&T. Go and check it out, you might land a code for a free game. If you're developing an indie game and want to post about it, follow these directions. If you don't, he'll break your legs! Hahaha! Seriously though.
Our rules have been updated and given their own forum. Go and look at them! They are nice, and there may be new ones that you didn't know about! Hooray for rules! Hooray for The System! Hooray for Conforming!

Apache mod_rewrite and 404s

SeguerSeguer Registered User regular
edited January 2009 in Help / Advice Forum
Hey guys, I've been trying to rewrite everything to a single index.php file to be handled there, but my Apache throws out a 404 at /wbcms/test for example before getting rewritten. Any ideas?
RewriteCond %{HTTP_HOST} ^*)$ [NC]
RewriteCond $1 !(^wbcms/index.php$) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(gif|jpg|png|css|js) wbcms/index.php

The first condition is for my dev area (need to rewrite differently on different hosts), the second is to stop infitnite looping (Apache stops itself at 10), and the next two were trying to combat the 404.

I adapted this from the A List Apart article, How to Succeed With URLs as well as a bunch of other resources I found.

Seguer on


  • flatlinegraphicsflatlinegraphics Registered User
    edited January 2009
    someone else might come in with something better, but this seems to work pretty good for me:
    RewriteRule ^inc(/)? - [S=3] 
    RewriteRule ^images(/)? - [S=2] 
    RewriteRule ^([^/.]+)(/)?$ page.php?page=$1
    RewriteRule ^([^/.]+)/([^/.]+)(/)?$ page.php?page=$1&sub=$2 [L]

    skips the 'inc' directory altogether, as well as the images folder. the regex pushes the requested url, with or without the trailing slash, to a variable. the site is at most 2 levels deep, so this works fine for me. so resolves to page.php?page=about&sub=me

    do you maybe need the [L] for last rule? ie, if the rule matches, stop processing.

    granted, i don't know much, but maybe this can help?

    flatlinegraphics on
  • SeguerSeguer Registered User regular
    edited January 2009
    Nope sorry, but thanks anyway. Mine can be any levels deep which is why I'm trying to get everything to be handled via php. Essentially you'd see something like and php would start working with "/projects/rewrite/how/to/make/it/work" ($_SERVER) to determine what content to show.

    EDIT: After some testing I manage to compress the rules
    RewriteCond %{HTTP_HOST} ^*)$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule !(\.(gif|jpg|jpeg|png|css|js)$|index.php$) wbcms/index.php [L]

    The -f and -d lines don't appear to do anything - Apache serves a 404 before attempting to apply this rule it appears, when it should be rewriting.

    Seguer on
Sign In or Register to comment.