SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot kemp's Avatar
    Join Date
    Aug 2004
    Location
    Campinas
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Passing RewriteCond back reference to all rules

    Here's my mod_rewrite syntax:

    Code:
    RewriteCond %{HTTP_HOST} ^([a-z]+)\.domain\.com [NC]
    RewriteCond %{HTTP_HOST} !^(www\.)domain\.com [NC]
    RewriteRule ^help/([_0-9a-z-]+)/([_0-9a-z-]+)/?$ http://subdomain.domain.com/index.php?1=help-article&2=0&3=$1&4=$2 [QSA,P]
    RewriteRule ^([_0-9a-zA-Z-]+)?/?([_0-9a-zA-Z-]+)?/?([_0-9a-zA-Z-]+)?/?([_0-9a-zA-Z-]+)?/?([_0-9a-zA-Z-]+)?/?([_0-9a-zA-Z-]+)?/?$ http://subdomain.domain.com/index.php?2=$1&3=$2&4=$3&5=$4&6=$5&7=%1 [QSA,L,P]
    My problem is that I need to pass the first RewriteCond back reference (%1) to all the RewriteRules, but that's not what happens. For some reason only the first active rule can access the value in %1.

    Any ideas?

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,650
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    kemp,

    To ALL the RewriteRules? It should - until you hit a Last flag (or get redirected OUT). Since your second RewriteRule is ANDed with the first, you'll not have it examined.

    Basically speaking, mod_rewrite is a very basic programming language which does NOT allow you to apply an earlier rule/variable with something in a different BLOCK statement.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •