Forum Moderators: coopster
<?
// Start the session and register the variables
SESSION_START();
header("Cache-control: private");
SESSION_REGISTER("EmptyField");
SESSION_REGISTER("Affiliate");
SESSION_REGISTER("LandingPage");
SESSION_REGISTER("CurrentPage");
$URL_data = explode("/", getenv("REQUEST_URI"));
// Get tracking information form the URL array
// Set Affiliate number
if ($URL_data[1]=="")
{
$_SESSION['Affiliate']="10000" ;
}
else
{
$_SESSION['Affiliate'] = $URL_data[1] ;
}
if ($LandingPage == "")
{
$_SESSION['LandingPage'] = $URL_data[2] ;
}
$_SESSION['CurrentPage'] = $URL_data[2] ;
// Write header redirect to appropriate link if $CurrentPage has "qx" in it
if (substr($CurrentPage, 0, 2) == "qx")
{ include '/var/www/html/php/ref.php'; }
// Include page sought if available
if(file_exists('/var/www/html/php/' . $CurrentPage . '.php'))
{
include '/var/www/html/php/' . $CurrentPage . '.php' ;
}
else
{
include '/var/www/html/php/main.php'; $CurrentPage='main';
}
?>
and the following in my htaccess --
DirectoryIndex ./php/content.php # index.htm # cgi-bin/y/d.cgi/?index-10000
# Start your engines
RewriteEngine on
# Set up the paths to follow
Options +FollowSymlinks -Indexes
RewriteBase /
# Enable access to Site Manager
ReWriteRule ^manager$ manager [L]
# Restrict Access to site resources images, etc.
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?payclerk\.com/.*$ [NC]
RewriteRule \.(gif¦jpe?g¦png¦bmp)$ - [F,NC,L]
RewriteRule ^\.htaccess$ - [F]
# Allow Perl Scripts to run
RewriteRule ^cgi-bin/y/d.cgi/?([a-z]+)-([0-9]+)$ - [NC,L]
# Allow Properly formatted URL to access content
RewriteRule ^([a-z0-9]{5})/([a-z0-9]+)/?$ ./php/content.php [NC,L]
# Allow Improperly formatted URL to access content and assign default AFF_NUM
ReWriteRule ^([a-z0-9]+)/?$ [mydomain.com...] [NC,R=301,L]
When I type in the URL
[mydomain.com...]
or
[mydomain.com...]
All works well and the correct variables are assigned where needed.
However, when I type in the URL
[mydomain.com...]
an incorrect variable is assigned and I get the page
[mydomain.com...]
where it should be
[mydomain.com...]
(Note: the number is a source tracking identifier much like .com?id=10000 or .com?id=10015)
I think my error is in the PHP I have written. Can anyone spot my error?
Many thanks for your help.
ReWriteRule ^([a-z0-9]+)/?$ [mydomain.com...] [NC,R=301,L]
If you really need to change the URL when it doesn't have the right format you should perhaps try something like:
ReWriteRule ^([a-z0-9]+)/?([^a-z0-9]+)$ [mydomain.com...] [NC,R=301,L]
That should default anything without a second argument, but it's probably going to conflict with something if you want to start adding extra arguments to the string.
Thanks for identifying the rule that was causing the problem. It helped me know where to make a correction, which I did by changing 10000 to $1. However the additional change you proposed created an error (Forbidden - you don't have permission)
ReWriteRule ^([a-z0-9]+)/?$ [mydomain.com...] [NC,R=301,L] gave me the correct result.
ReWriteRule ^([a-z0-9]+)/?([^a-z0-9]+)$ [mydomain.com...] [NC,R=301,L] gave the error.
Perhaps there is something else that causes the double variable to fail, so I'll just stick with the version that now works until it fails.
Again thanks, I couldn't see the forest for the trees.
ReWriteRule ^(([a-z0-9]+)/?([^a-z0-9]+))$ [mydomain.com...] [NC,R=301,L]
Can be sure though, I have no way of testing at the moment.