forced redirect with mod_rewrite in htaccess?

2 replies
Hi fellow warriors,

I'm not quite sure how to proceed with a tracking script which uses a mod_rewrite with htaccess.

For each link I want to track, the script gives me a URL like www.mydomain.com/recommends/XXX.

The paths and directories are set up ok, mod_rewrite is enabled. The htaccess-code which came with the script is as follows:

Code:
RewriteEngine on 
RewriteBase /recommends
RewriteRule ^/?(.*) /go/go.php/$1 [QSA]
When I put this as .htaccess into the "recommends" directory, I get an error message which says something like "no input file specified".

By trial and error, I found that when I change the last line to

Code:
RewriteRule ^/?(.*) /go/go.php/$1 [R,QSA]
everything is working just fine.

Now, what I don't understand:

  • Why do I have to enforce the redirect with the additional "R"?
  • If I add "R", although the programmer originally hadn't included it, could I run into any trouble?
  • Should I use "R=301" (permanently moved) or "R=302" (temporarily moved) for a tracking script? I only want to get some data about which adds convert better than others...
  • Oh, and should I include an L tag at the end of the last line, too?
Sorry for the beginner's questions. I've been searching for several hours now, and there is a ton of info about mod_rewrite, but nothing really answers my questions -- guess they are just too basic...

Any help appreciated,

milkyway
#forced #htaccess #modrewrite #redirect
  • Profile picture of the author munkyscripts
    Not sure but an alternate way to track the clicks is to use js. this is code i use.
    Code:
    <script language="JavaScript" type="text/javascript"> 
    <!-- 
    function trackclick(id) {
    if(document.images){ 
        (new Image()).src="/wp-content/plugins/munkytoplist/out.php?id="+id;
    } 
    return true;
    }
    // --> 
    </script>
    Then in the a href i add onclick="return trackclick('1');" where 1 is the id of whatever you are tracking
    {{ DiscussionBoard.errors[1312796].message }}
    • Profile picture of the author milkyway
      Hi munkyscripts,

      thanks for your answer!

      I already have a tracking script which allows me to track what I need and displays everything very nicely. It's based on JavaScript, too, but does some other fancy stuff which I couldn't program myself.

      I was just wondering about how to proceed with the mod_rewrite, in particular if I can mess anything up when I add "R" and "L" tags, and if I should use temporarily or permanently moved redirects.

      As I said, I'm new to this htaccess stuff and am just not sure how to proceed...

      Thanks for your help -- much appreciated,

      milkyway
      {{ DiscussionBoard.errors[1313181].message }}

Trending Topics