homepage Welcome to WebmasterWorld Guest from 54.167.41.199
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Rewriting Troubles
nick279




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

#1
RewriteRule ^_images/c/([0-9]+)/$image.php?id=$1 [L]
#2
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} (.+)
RewriteRule (.*?) index.php?url=%{REQUEST_URI}&query=1&%1 [L]
#3
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)

Basically
#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)

 

nick279




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

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]

jdMorgan




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

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 "_".

Jim

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved