#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2016
    Posts
    9
    Rep Power
    0

    Smile .htaccess rewrite with variables and queries


    Hey Everyone, I am trying to code some rewrites in my .htaccess file to allow it to read queries:

    eg. utm_expid=

    and dynamic url parmameters

    eg. a-free-video-([0-9]+)$

    Bellow is my working code for making dynamic variable url rewrites

    Code:
    # Offers -> VSL B
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    
    RewriteRule ^b-free-video-([0-9]+)$ offers/vsl_b/b-free-video-$1 [NC,L]
    Here is were I have tried to add queries.

    Code:
    # Offers -> VSL A
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{QUERY_STRING} ^utm_expid=.+ [NC]
    
    RewriteRule ^a-free-video-([0-9]+)$ offers/vsl_a/a-free-video-1?%{QUERY_STRING}? [NC,L]
    Any help would be greatly appreciated
  2. #2
  3. Headless Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,977
    Rep Power
    9647
    Query strings will be included automatically if you don't modify them in your rewriting. So with the first version, going to
    Code:
    b-free-video-123?utm_expid=abc
    will rewrite to
    Code:
    offers/vsl_b/b-free-video-123?utm_expid=abc
    With the second, if you remove the ?%{QUERY_STRING}? then it will rewrite from
    Code:
    a-free-video-123?utm_expid=abc&xyz=789
    to
    Code:
    offers/vsl_a/a-free-video-1?utm_expid=abc&xyz=789
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2016
    Posts
    9
    Rep Power
    0
    Got it all working, thanks for your help

IMN logo majestic logo threadwatch logo seochat tools logo