Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2003
    Location
    AR
    Posts
    2,382

    Pretty urgent help needed (.htaccess/PHP)

    I am completely stumped on this one.

    Let me give you the project description here..

    Basically this is going to be a large, multi-domain, redirection script, which will be part of a much larger project. The main goal of this is to track which links were clicked, which sites were most popular, etc...

    My main problem is that the script will be hosted on one main site. There will be hundreds of individual sites all using said script for redirection, and each site will need to place a certin .htaccess code on their site to redirect their 'links' (IE, any folder or file that doesn't exist on their site) to the PHP script, hosted on a separate site/server.

    My issue is that I can't figure out how to reliably transport the full URL that the user came from to the PHP script. I was thinking something along the lines of (pseudo)

    If URI requested is not an existing directory and is not an existing file and is not the site root (site.com/) then redirect to serversite.com/phpscript?refer=referring_url

    phpscript, then, would take 'referring_url', look up its entry in the database, and seamlessly redirect to the redirect URL.

    So, what .htaccess code would you use to redirect the user to the PHP script?

    My .htaccess skills are rusty, at best, but the following is what I came up with...But it doesn't seem to be redirecting anywhere at all...

    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !./.
    RewriteRule ^(.*)/?$ http://site.com/phpscript.php?referrer=$1 [R,L]
    But all I get is the server standard 404..which is odd

    Any help or input at all here is appreciated..

    Kevin

  2. #2
    Join Date
    Feb 2003
    Location
    AR
    Posts
    2,382
    I'm an idiot (and realized it after posting)

    That .htaccess code wasn't working because I was placing it in a subdirectory....

    My problem now, however, is that it is directing to site.com/script.php?referrer=requested_file_name...

    But I need it to redirect to
    site.com/script.php?referrer=full_requested_url

    How do I change that rewriterule line to accomplish that?

    THanks,
    Kevin

  3. #3
    Join Date
    Feb 2003
    Location
    AR
    Posts
    2,382
    Well, I came up with A solution, that should work for all sites, I do believe...Posting it here for future reference..

    Code:
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !./.
    RewriteRule ^ http://site.com/redirect.php?referrer=%{HTTP_HOST}%{REQUEST_URI} [R,L]

Posting Permissions

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