I have the following data structure in PHP (shortened for brevity) in the array $job:
(
[jobid] => 33541166
[country] => South Africa
[subcounty] => Somerset West
[position] => Administrator (R7 500 p.m.)
)
I have the following .htacccess rule:
RewriteRule job/(.*)/(.*)/(.*)$ /info.php?jobid=$1&position=$2&city=$3
This rule intermittently works, but the reason why eludes me. Take the examples below:
https://site.co.za/job/33541166/administrator_r_7_500_pm/somerset_west
https://site.co.za/job/33541166/administrator_r_7_500_px/somerset_west
The job structure in the PHP array is the same for both. The URL is purely cosmetic, really, as the only criteria I use to retrieve the job from the database is the job ID (e.g., 33541168).
As you can see, the first URL has “pm” and the second one has “px”, otherwise they are the same. The first link DOES NOT display the job, redirects to homepage, and the second one DOES display the job correctly, yet, the “px” is not in the position string above.
Then there is a completely different job:
https://site.co.za/job/33541168/receptionist_for_general_practitioner/durban_north
And it works 100% with no anomalies.
The code used to construct the URL to be clicked on the page is this ($jobid is used in $position and $city whenever these fields are not present (historical data issues):
if (!empty($v['position'])) {
$position = preg_replace("/p{P}/", '', trim($v['position']));
$position = strtolower(str_replace(' ', '_', $position));
} else {
$position = $jobid;
}
if (!empty($v['subcounty'])) {
$city = preg_replace("/p{P}/", '', trim($v['subcounty']));
$city = strtolower(str_replace(' ', '_', $city));
} else {
if (!empty($v['country'])) {
$city = preg_replace("/p{P}/", '', trim($v['country']));
$city = strtolower(str_replace(' ', '_', $city));
} else {
$city = $jobid;
}
}
And the link is structured as follows:
<a style="color: #ffffff !important;"
href="<?php echo $fullurl; ?>/job/<?php echo $job['jobid']; ?>/<?php echo $position; ?>/<?php echo $city; ?>">
<?php echo $job['position']; ?>
</a>
Notes, in case needed:
`$job` is the PHP array containing the entire job particulars, as shown in shortened fashion above,
`$position` and `$city` are the modified strings for use in the URL.
I have initially thought maybe a duplicate ID (even though the DB has autoincrement on the jobid column) or a duplicate description, but that does not appear to be the case. I also considered that the . and the ( and ) in the administrator job position might be causing havoc, but I believe it shouldn’t because of the regex I used in my PHP code. To confirm that, I removed these characters in a test, and still does not work consistently.
Every job I have checked shows the URL to click on in the browser in the correct format, so I do not think the PHP code above is fundamentally flawed, except maybe not optimal.
I do not have access to Apache server logs at this time.
Any ideas will be much appreciated.