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

Apache Web Server Forum

    
Using back references in mod rewrite
milanmk

5+ Year Member



 
Msg#: 3411359 posted 12:01 pm on Aug 2, 2007 (gmt 0)

I have the following rule.

RewriteRule (^(dir1¦dir2)/dir3/(page1¦page2)-([0-9])+\.jpg$) /test.php?src=$1 [L]

Now if i want to use back references in RewriteCond then am i correct in guessing them like this:-

$1 = dir1/dir3/page1-001.jpg
$2 = dir1
$3 = page1
$4 = 001

If so, i can use them in RewriteCond like

RewriteCond %{HTTP_REFERER}!^http://example\.com/$2/dir4/$3-$4\.htm [NC]

Milan

 

milanmk

5+ Year Member



 
Msg#: 3411359 posted 1:57 pm on Aug 2, 2007 (gmt 0)

I think we can only use back references in TestString and not in CondPattern, right?

Milan

jdMorgan

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



 
Msg#: 3411359 posted 4:34 pm on Aug 2, 2007 (gmt 0)

Correct for both your analysis of the back-reference variables and your question about the test-string.

To determine back-reference variable numbers, count the left parentheses.

You can use back-references only in the test-string on the left side of a RewriteCond, and not in the pattern on the right.

Also, be aware that if you use the "Referer is NOT" construct, you must make provisions in the logic so that the code behaves correctly when the referer is blank, which it will be quite often, even for legitimate requests.

Jim

[edited by: jdMorgan at 4:34 pm (utc) on Aug. 2, 2007]

milanmk

5+ Year Member



 
Msg#: 3411359 posted 4:57 am on Aug 3, 2007 (gmt 0)

Thanks Jim for confirming it.

Milan

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