Answer this PHP question and I'll Paypal you $5

by Jeff S
7 replies
** The first person to post the solution to this, I'll PM you to get your Paypal address and I'll send you $5

QUESTION: I'm trying to figure out the best way to redirect a vistitor who types in my URL with a coupon code (see below) to another url with a variable populated. For example, when someone types the following:

http://www.mysite.com/A101

they are redirected to:

http://www.mysite.com/page.php?coupon=A101 (PREFERRED SOLUTION)

or to:

http://www.mysite.com where a form field is prepoulated with the A101 code so they only need to click a submit button

Right now the mysite.com/A101 is treated as a 404 and I tried to do a custom PHP to get the URL using SERVER_NAME and PHP_SELF but it's just showing the 404.php page. I don't want to have to create files/directories for A101 anywhere, it needs to dynamically do it.

I'm running on Apache/PHP

Thanks in advance!
#answer #paypal #php #question
  • Profile picture of the author tjs1954
    Jeff,

    When I want a browser to leave one site and go to another I just put this code in the meta tags of the index page, <meta HTTP-EQUIV="REFRESH" content="0; url=http://www.yourdomain.com/index.html"> or whatever page you want it to go to.

    The zero is how many seconds you want it to wait before it switches.
    {{ DiscussionBoard.errors[1658313].message }}
    • Profile picture of the author Jeff S
      Originally Posted by tjs1954 View Post

      Jeff,

      When I want a browser to leave one site and go to another I just put this code in the meta tags of the index page, <meta HTTP-EQUIV="REFRESH" content="0; url=http://www.yourdomain.com/index.html"> or whatever page you want it to go to.

      The zero is how many seconds you want it to wait before it switches.
      Yes, that is how I typically do simple redirects, but what I'm trying to do is a bit more complicated than that.
      {{ DiscussionBoard.errors[1658366].message }}
  • Profile picture of the author Trey Walter
    Hi Jeff,

    you can also use URL rewriting to do that. (I think this would be the best solution if there are a lot of different coupon codes.)

    Here's how to do it:
    mod_rewrite: A Beginner's Guide to URL Rewriting [Apache & IIS Configuration]

    Trey
    {{ DiscussionBoard.errors[1658333].message }}
    • Profile picture of the author Jeff S
      Originally Posted by Trey Walter View Post

      Hi Jeff,

      you can also use URL rewriting to do that. (I think this would be the best solution if there are a lot of different coupon codes.)

      Here's how to do it:
      mod_rewrite: A Beginner's Guide to URL Rewriting [Apache & IIS Configuration]

      Trey
      Hey Trey,

      Thanks for pointing me in the right direction...mod rewrites seems like the way to go. I'll PM you for your Paypal address to send you the $5!

      - Jeff
      {{ DiscussionBoard.errors[1664772].message }}
  • Profile picture of the author m4rx
    Well I would with what Trey said.
    You could use mod_rewrite to redirect your page.

    Make a file called .htaccess and have the contents be:
    RewriteEngine on
    RewriteRule ^yourURL$ /page.php?coupon=yourURL [R]

    and whenever someone types in yoursite.com/yourURL they will be redirected to the page.php?coupon=yourURL

    You can see a demo by typing m4rx.com/coupon and it will so you the redirect to cat.php?coupon=coupon

    This is just like when companys do this. You could modify it to show R=301(Found). This is the industry standard and works well.
    http://en.wikipedia.org/wiki/HTTP_302
    Don't use 301(Moved Permanatly) as then the URL becomes useless when crawled, and because I would rarely use it(except after major remodeling ;] ).

    Any help configuring it, PM me.
    --m4rx
    Signature
    We are what we repeatedly do. Excellence, then, is not an act, but a HABIT. ~Aristotle
    Bored. Learn everything you need to know about Organic Gardening.
    {{ DiscussionBoard.errors[1659555].message }}
  • Profile picture of the author customertools
    m4rx has the solution I would choose. unless you want to modify the php code. (which would be very easy to do)
    {{ DiscussionBoard.errors[1664623].message }}
  • Profile picture of the author rukki
    Nice idea with Paypal. It might be useful sometimes...
    {{ DiscussionBoard.errors[1664749].message }}

Trending Topics