php header location causes redirect loop
Hi
Hope someone can help with this, as it is a general php question, not related to a problem with any WA product.
I've moved from parameter based pages to 'friendly urls', using the following excerpt from my htaccess file:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/content\.php\?su=([^\s&]+)&PgID=(\d+)&pu=([^\s&]+) [NC]
RewriteRule ^ /%1/%2/%3? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/(\d+)/([^/]+)\.html$ /content.php?su=$1&PgID=$2&pu=$3 [L,QSA]
All the above works fine.
However, if a visitor goes to a page from a search engine, say, and the pg_url has been updated; I'd like to change the url shown in the address bar.
The correct page is still found, from the PgID number, but the pg_url in the search engine might be /page-name.html but the new name is actually /better-name.html
I've tried this (from http://3x.impresspages.org/cms/answers/545/problem-with-redirect-in-htaccess-url-rewriting) in php using the following (and variants of it), but the page always fails because of a redirect loop;
<?php
if ($_SERVER['REQUEST_URI'] <> '/". $WADApages->getColumnVal("short_url"). "/". $WADApages->getColumnVal("PgID") ."/". $WADApages->getColumnVal("pg_url") .".html') {
header("HTTP/1.1 301 Moved Permanently");
header("Location: /". $WADApages->getColumnVal("short_url"). "/". $WADApages->getColumnVal("PgID") ."/". $WADApages->getColumnVal("pg_url") .".html");
exit;
}
?>
Very grateful to any pointers - I have tried numerous variants with the same results.
Many thanks
Chris