• Hope this belongs here. Need help with my htaccess code.

    I want to turn these URLS:
    /mysite/site1/offer/
    /mysite/site2/offer/
    /mysite/site1/offer/?name=tom&email=test@test.com

    into to this:
    /mysite/site1/?page=offer
    /mysite/site2/?page=offer
    /mysite/site1/?page=offer&name=tom&email=test@test.com

    So that wordpress ignores ‘/offer/’ and instead passes the url parameter to the custom template.

    Can this be done?

    I tried this:
    RewriteRule /mysite/([^/]+)/([^/]+)/$ /mysite/$1/?pg=$2 [L,QSA,NC]

    But I know it’s missing the bit to capture the other url params but not sure how to write this.

    Any help is greatly appreciated. Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Dion

    (@diondesigns)

    Maybe something like this?

    RewriteCond %{QUERY_STRING} .+
    RewriteRule (.*?)/offer/\?.* $1/?page=offer&{QUERY_STRING} [L]
    RewriteRule (.*?)/offer/$ $1/?page=offer

    I’m sure it could be done more efficiently. Also, if you have a VPS or dedicated server, once you have this working to your satisfaction, give some thought to adding this to your main httpd.conf file inside a <Directory> directive. HTACCESS files are hard on the server because they must be compiled on every page load. Directives in httpd.conf are compiled once at startup and cached.

    Thread Starter petron99

    (@petron99)

    Thanks for the response DD. I can get it to partially work on this htaccess tester but none of it works on the server. On the server I’m using $_SERVER[‘REQUEST_URI’] to check if the url is broken down like I want but it’s just not working at all. But all I see is just the full path no parameter.

    When testing on the htaccess tester this works:
    RewriteRule (.*?)/offer/$ $1/?page=offer

    It changes this:
    http://domain.com/mysite/myfolder/offer/

    To this:
    http://domain.com/mysite/myfolder/?page=offer

    And that’s what I want but the other part isn’t working

    This does not work on the htaccess tester:

    RewriteCond %{QUERY_STRING} .+
    RewriteRule (.*?)/offer/\?.* $1/?pg=offer&{QUERY_STRING} [L]

    This should change:
    http://domain.com/mysite/myfolder/offer/?asdf=asdf

    To this:
    http://domain.com/mysite/myfolder/?page=offer&asdf=asdf

    But it doesn’t.

    Thanks again for your help.

    Dion

    (@diondesigns)

    If you don’t mind having an extraneous ampersand in some cases, then if the checker is correct, this should work:

    RewriteRule (.*?)/offer/$ $1/?page=offer&%{QUERY_STRING}
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Need help with RewriteRule – want to pass part of url as parameter’ is closed to new replies.