Forum Moderators: phranque
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /imagecat\.php\?(catid=1&)?subcatid=195\ HTTP/
RewriteRule ^imagecat\.php$ http://www.example.com/jenna-pietersen-wallpapers.html? [R=301,L]
#
RewriteRule ^jenna-pietersen-wallpapers\.html$ /imagecat.php?catid=1&subcatid=195 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /image\.php\?imgid=([0-9]+)&
RewriteRule ^image\.php$ /my-special-script.php?imgid=%1 [L] <?php
$imgid = $GET[imgid];
$validid = //read database and check if this ID is valid.//
# IF the ID is not valid, immediately send headers:
IF ($validid = false)
{HEADER "Status: HTTP/1.1 404 Not Found";}
# IF the ID is valid, construct redirect URL and send headers:
IF ($validid = true)
{
$titleslug = //Read database and get URL title slug for this ID.//
$server_url = $_SERVER['HTTP_HOST'];
IF (preg_match('/^www\./', $server_url) !== true)
{$server_url = "www." . $server_url;}
$new_url = 'http://' . $server_url . '/' . $imgid . '-' . $titleslug;
HEADER "Status: HTTP/1.1 301 Moved Permanently";
HEADER "Location: " . $new_url;
}
?> RewriteRule ^[0-9]+-(.*)$ /image.php?imgid=$1&titleslug=$2 [L] <?php
$imgid = $GET[imgid];
$titleslug = $GET[titleslug];
$validid = //read database and check if this ID is valid.//
# IF the ID is not valid, immediately send headers:
IF ($validid = false)
{HEADER "Status: HTTP/1.1 404 Not Found";}
# IF the ID is valid but the titleslug is not 100% correct for this ID, construct redirect URL and send headers:
$titleslugfromdb = //read database and get the titleslug for this ID.//
IF ($titleslug !== $titleslugfromdb)
{
$server_url = $_SERVER['HTTP_HOST'];
IF (preg_match('/^www\./', $server_url) !== true)
{$server_url = "www." . $server_url;}
$new_url = 'http://' . $server_url . '/' . $imgid . '-' . $titleslug;
HEADER "Status: HTTP/1.1 301 Moved Permanently";
HEADER "Location: " . $new_url;
}
ELSE
{
# IF the ID is valid, and the titleslug is 100% correct for this ID then serve the content
Serve the content as before - i.e. code from your existing script.
}
?>