Solved

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

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

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Running Guacamole on port 80 5 248
IPA - can it be run on a web server? 3 205
Apache 2.2 on Windows 2008 32 83
mod_rewrite # anchor problem. 6 30
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…
If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
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…

792 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