Forum Moderators: phranque

Message Too Old, No Replies

help w/mod rewrite

         

noooob

4:23 pm on Mar 13, 2008 (gmt 0)

10+ Year Member



Hi All,

I am using a tracking software which generates a unique ID value for each visit to a page. My site uses .htaccess redirects for all links to hide affiliate links.

ex.
Redirect /faq.html [someaff.site.com?x=faq...]

I need to append the unique ID, generated by php as <?php echo var; ?> , to the redirected affiliate link for tracking.

i.e.
[someaff.site.com?x=faq&id=uniqueid...]

I am able to pass the unique ID as a variable to the /faq.html link as:

/faq.html?id=uniqueid

Can someone advise me on using Rewrite to be able to pass this unique ID as needed to the redirect destination?

Kind Regards.

jdMorgan

3:45 am on Mar 14, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If I'm understanding your goal and your operating environment, then you'll need to use mod_rewrite, rather that mod_alias. That is, switch from using a "Redirect" directive to using mod_rewrite directives.

Something like:


Options +FollowSymLinks
RewriteEngine on
#
RewriteRule ^faq\.html$ http://someaff.site.com/?x=faq [QSA,R,L]

Here, the [QSA] flag tells mod_rewrite to append the "x=faq" query string to any query string already attached to the faq.html request, rather than replacing it.

You may or may not need the first line. It can cause errors if it's needed and not present, or if it's not needed and it is present. It can also cause errors when present, even if needed, but in that case, it means you can't use mod_rewrite on that server. Since all this depends on your server's configuration, you have to test to find out. A 500-Server Error response indicates that it's not working.

You only need the second line if there isn't already a "RewriteEngine on" above this new code in your .htaccess file.

All changes from the code you posted are intentional.

Jim

[edited by: jdMorgan at 3:46 am (utc) on Mar. 14, 2008]