Solved

.htaccess check for 'page=' in page URL?

Posted on 2013-06-14
2
298 Views
Last Modified: 2013-06-15
0
Comment
Question by:sabecs
  • 2
2 Comments
 
LVL 29

Expert Comment

by:Randy Downs
ID: 39249515
You can conditionally redirect as in the example below. Once the conditions are met the files are dealt with via a script. Hope this helps.


#Condionally redirect old  pages via script if not the index.html or state 
RewriteCond %{REQUEST_URI} !^/venues/index\.html$  [NC]
RewriteCond %{REQUEST_URI} !^/venues/states/.*$  [NC]
RewriteRule ^venues/(.*) scripts/redirect-v.php?d=$1&%{QUERY_STRING} [L]
RewriteRule ^venues/states/(.*) scripts/redirect-state.php?d=$1&%{QUERY_STRING} [L]

Open in new window


redirect-v.php
<?
ob_start();

// Redirect old links
$file = $_GET['d'];
$file = strtolower($file); 

// Catch special cases that had -and- substituted for &
$file = str_replace("-and-", "___", $file);
$file = str_replace("-", "_", $file);

// Catch old pages that end with .htm and .shtml
//$file = str_replace(".htm", ".html", $file);
$file = str_replace(".shtml", ".html", $file);
//$file = str_replace(".php", ".html", $file);

$new_url = 'http://www.site.com/venue/' . $file;
//echo "<br /> New URL is " . $new_url ;

// redirect
$ext = substr(($file), -4); 
//echo "<br /> Extension is " . $ext ;

if ($ext=="html")
{
//	echo "<br />  Redirect old page. "; 
//	echo "<br /> URL ends in html. Redirect to ". $new_url; 
	header("HTTP/1.1 301 Moved Permanently");
	header('Location: ' . $new_url);
}
else {
	$new_url=$new_url.'_tickets.html';
//	echo "<br />  Redirect page. "; 
//	echo "<br /> no extension - Append _tickets.html to url. Redirect to ". $new_url; 
	header("HTTP/1.1 301 Moved Permanently");
	header('Location: ' . $new_url);
}


?>

Open in new window

0
 
LVL 29

Accepted Solution

by:
Randy Downs earned 500 total points
ID: 39249520
In my script I am checking for files that ended in .htm and .shtml. I then replaced those with .html. Then I back up 4 characters (i.e. html) and Append _tickets.html to the file.

You can do something similar keying on the text "page".
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question