Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Rewriting Troubles



10:22 am on Dec 10, 2008 (gmt 0)

5+ Year Member

RewriteRule ^_images/c/([0-9]+)/$image.php?id=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} (.+)
RewriteRule (.*?) index.php?url=%{REQUEST_URI}&query=1&%1 [L]
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9\-\/\.\_]+)$ index.php?url=$1 [L]

Hi all,

I'm trying to perform a rewrite for all requests to index.php (file which handles urls)

This file then looks at the url and decides what to do from there (redirect, display, 404)

So far, it's working in pieces - however, certain rules are overwriting others. In particular, rule #2 seems to being satisfied every time and I'm not sure why (for images etc)

#1 - rewrite is used to display images/resources from database
#2 - should only be triggered if there is a query string present in the url (passes through all get variables - can be read in PHP as key/value array)
#3 - should be triggered if above rules are not met (e.g. everything else)


11:13 am on Dec 10, 2008 (gmt 0)

5+ Year Member

Have just had a read through a series of webmasterworld posts and found a couple of ideas which seem to be working. Would still appreciate any feedback, as could be killing server/memory

RewriteRule ^_images/c/([0-9]+)/$ image.php?id=$1 [L]
RewriteCond %{THE_REQUEST} \?
RewriteRule (.*?) index.php?url=%{REQUEST_URI}&query=1&%{query_string} [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9\-\/\.\_]+)$ index.php?url=$1 [L]


2:22 pm on Dec 10, 2008 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

What is the intent of the pattern "(.*?)" ?

Although this is standard notation for a "non-greedy" match on zero or more of any character, this notation is not typically supported by all servers, and should be avoided.

Be aware that the only characters you need to escape within alternate character [groups] are "]", "-", and also "^" if it appears first in the list of alternates. You do not need to escape "/", ".", or "_".



Featured Threads

Hot Threads This Week

Hot Threads This Month