Wednesday, December 28, 2011

If not found, redirect to a different URL to check

SkyHi @ Wednesday, December 28, 2011

# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.

##.htaccess
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ([^/\.]+)$ http://www.rose1.com/check_url.php?string=$1 [L]


#check_url.php
session_start();
require_once ("functions.php");
$db = new db_mysql();
$file_db = $db->getValue ("SELECT pl_name FROM promo_link");
$file_db2 = $db->getValue ("SELECT sl_name FROM specials_links");


$str = $_SERVER['REQUEST_URI'];
$str_arr = explode ("/", $str);
$file_name = $str_arr[count ($str_arr) - 1];

if ($file_name == $file_db) {
   header ("Location: promotions/booking.php");
   exit;
}


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

... means that if the file with the specified name in the browser doesn't exist, or the directory in the browser doesn't exist then procede to the rewrite rule below

REFERENCES
http://www.sitepoint.com/forums/showthread.php?259764-What-does-this-mean-RewriteCond-REQUEST_FILENAME-!-f-d
http://www.datakoncepts.com/seo