redirect
Redirect From HTTPS To HTTP Using PHP
Fri, 04/17/2009 - 15:28 | by philipnorton42If you have a site with parts of it using SSL, but want to turn it off for mundane pages like the blog section then use the following code. This uses the $_SERVER['HTTPS'] variable to see if HTTPS is turned on, if it is then a header is issued and the page redirected.
if ($_SERVER['HTTPS'] == 'on') {
$url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
header('Location: ' . $url, true, 301);
exit();
}
You can turn it back on again on your secure pages using the opposite.
Using .htaccess To Redirect HTTPS To HTTP
Thu, 04/09/2009 - 09:12 | by philipnorton42To redirect from HTTPS to HTTP on the home page only using the following rule.
RewriteCond %{HTTPS} on
RewriteRule ^/?$ http://%{SERVER_NAME}/ [R=301,L]
The variable %{HTTPS} will be either "on" or "off" and will be enabled even if SSL is not installed on your site. The rule above sees that HTTPS is on and redirects the home page to the HTTP version. You can even chain lots of rules together like this.
JavaScript Redirects
Wed, 03/11/2009 - 11:07 | by philipnorton42There are two main ways in which to redirect the browser using JavaScript, both of which look at the location of the window object. These are the location.href property and location.replace function.
location.href
The following example will cause the page to redirect to another page, keeping the browser history. This might seem like a minor point, but if you redirect a user to another page they will be able to click back, which will mean that they are redirected again.
Using Redirection Inside a Plugin In Zend Framework
Mon, 02/02/2009 - 18:15 | by philipnorton42I had a situation the other day where I had an application in Zend Framework and I wanted to redirect a user to another page. This is fine if you are inside a controller as you can use the _redirect() controller helper, but in this instance I was running the code from inside a plugin and so therefore didn't have direct access to the controller.
Redirect One Directory To Another With .htaccess
Mon, 05/19/2008 - 08:55 | by philipnorton42To stop access to a directory (and anything in that directory) all you need is a simple RewriteRule.
RewriteEngine on RewriteBase / RewriteRule ^exampledirectory/(.*)$ / [R=301,L]
In this example, if this .htaccess file resides in the root directory of the site and you try to access anything within /exampledirectory you will be redirected back to the root folder. To redirect to another folder (like anotherdirectory) on your web server use the following rule.
PHP Page Redirection
Wed, 03/12/2008 - 22:34 | by philipnorton42To redirect to a different page using PHP you can use the header() function with the parameter 'Location: ' and the destination of the redirect.