Solved

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

Posted on 2013-06-14
2
288 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

706 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now