Page forwarding (redirect)

Example: The page will be redirected to a subdirectory.

Adoption: phpwcms is located in the subdirectory http://example.com/wcms/

Standard entries in the conf.inc.php

// site values
$phpwcms['site']              = 'http://'.$_SERVER['SERVER_NAME'].'/';
 
// paths
$phpwcms['DOC_ROOT']          = $_SERVER['DOCUMENT_ROOT'];
$phpwcms['root']              = 'wcms';         //default: ''


Solution 1:

http://example.com/.htaccess

RewriteEngine on
RewriteRule ^(.*) http://example.com/wcms/ [R,L]


Solution 2:

http://example.com/index.php

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location:wcms/");
exit;
?>


Forwarding with error 404:

If a requested page does not exist, it is often desired that a custom error page is produced with custom layout.
Under normal conditions the given layout of the page “home” was delivered with the error message of the range “error”.

If we write in the “error” area in the template for “home” the following redirect, an error page with a separate layout can be created.
This error page lies typically in a hidden range of the system (ADMIN → site structure → frontend menu status: [x] hide).

http://example.com/index.php?404


Docu: –
Forum: mod_rewrite + RewriteRule + errorDocument

Author: Heiko H.
CMS Version: >= 1.26
Version: V1.0

Tag: –
fileiname: –
Folder: –

Condition:/config/phpwcms/conf.inc.php

  • $phpwcms['allow_ext_render'] = 1;



[PHP]
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://example.com/index.php?404" );
exit;
[/PHP]


Forwarding with error 404 (second try):

Another attempt for dealing with “not found” or “moved elswhere”. See forum: http://forum.phpwcms.org/viewtopic.php?p=127140#p127140

Set up a (potentially global) 404 file

Create a file “moved.php” with the following content (or as you like) and throw it somwhere ;) (your php root will be best for testing purposes, but it could be anywhere):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Content not found or moved elsewhere</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="content-style-type" content="text/css" />
<style type="text/css">
 
html {
    overflow : hidden;
}
 
body {
    color: #fff;
    background-color: #312d4d;
    padding: 0;
    margin: 0;
    border:0;
    overflow: hidden;
    font-size:67.5%;
}
 
#main {
    background-color: transparent;
    padding: 0.7em;
    border: 0.3em dashed #b9821a;
    margin: -16.5em 0 0 -25em;
    position:absolute;
    top: 50%;
    left: 50%;
    width: 50em;
    height: 33em;
    font-family: "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
    font-size:1.1em;
}
h2 {
    color:#FF3300;
    font-size:1.5em;
}
h4 {
    color:#FF3300;
    font-size:1.2em;
}
a {
    color:white;
    font-weight:bold;
}
hr {
    color: #EEEEEE;
    background-color: #EEEEEE;
    height:0.2em;
}
#form {
    background-color:#eeeeee;
    color:#222222;
    border:0.2em solid #ff0000;
    width:20em;
    margin:0 auto;
    text-align:center;
}
#form .input {
    background-color:#ffffee;
    color:#222222;
    border:0.2em solid #ffffff;
}
#form .submit {
    background-color:#eeeeee;
    color:#222222;
    border:0.2em solid #ffffff;
}
 
</style>
</head>
<body bgcolor="#ffeeee">
<div id="main">
  <h4>The requested page could not be found or doesn't exist any longer! Please excuse the inconvenience!</h4>
    Obviously your bookmarks are a little bit outdated. Please follow the link we have provided for you beneath:<br />
  <h4>Die angefragte Seite konnte nicht gefunden werden! Entschuldigen Sie bitte diese Unannehmlichkeit!</h4>
    Offensichtlich haben Sie noch einige veraltete Bookmarks gespeichert. Bitte benutzen Sie den folgenden Link, um zu unserer neuen Seite zu gelangen:<br />
    <h2><a href="mysupidupidomain.tld/index.php">mysupidupidomain.tld</a><a href="http://www.myothersuperdom.tld1/index.php">myothersuper.tld1</a>, <a href="http://www.anothersupertotal.tld2/index.php">anothersupertotal.tld2</a></h2>
    <br />
<script type="text/javascript">
  var GOOG_FIXURL_LANG = 'de','fr','ch','nl','en','it';
  var GOOG_FIXURL_SITE = 'http:/mysupidupidomain.tl/','http:///www.myothersuperdom.tld1/','http://www.anothersupertotal.tld2';
</script>
<script type="text/javascript"
    src="http://linkhelp.clients.google.com/tbproxy/lh/wm/fixurl.js"></script>
</div>
</body>
</html>

We need some frontend_init-script

This will become a frontend_init script. Call it 404_forwarding.php and throw it into /template/inc_script/frontend_init/

<?php
// compare against current domain and redirect to correct if neccessary
 
if(isset($LEVEL_ID[1])) {
//check active Domains
 
if($LEVEL_ID[1] == 11 && strpos(PHPWCMS_URL, 'mysupidupidomain.tld') === false) {
   header( "HTTP/1.1 301 Moved Permanently" );
   headerRedirect('http://mysupidupidomain.tld/index.php'.returnGlobalGET_QueryString());
   }
}
if($aktion[0] == 0 && !isset($_GET['adclickval'])) {
 
switch ($_SERVER["SERVER_NAME"]) {
 
case 'mysupidupidomain.tld':
            header( "HTTP/1.1 301 Moved Permanently" );
 
            headerRedirect('index.php?aid=1255');
            break;
 
default:header( "HTTP/1.1 301 Moved Permanently" );
            headerRedirect('moved.php');
            break;
  }
}
 
?>

What does this script do?

It will check if a queried page is existing within your system. Perhaps you did change an alias some while ago and now the bookmarks of your friends are going wonk. phpwcms' frontent_init-script will now take over and call a little page you've set up already, I bet. No?

Create your error article

So go ahead and create a new page (article) with an excusion for the worries, a search mask and whatever you like - it's your own phpwcms 404 error page ;) . Don't forget to save it into a hidden category (frontend menu status checked to [x]hide). This way the error page doesn't belong anywhere and can't mislead anybody.

Edit your 404_forwarding.php

Check the article id of your newly created article (you know how to do that), edit 404_forwarding.php and enter it instead of that 1255 (because this ArticleID from further above is just an example, not more) to reflect your special article ID. If somebody tries to search your phpwcms installation by using directory structures like domain.tld/heavy/ the script is passing the force over to moved.php.

It's for a multidomain setup too

But this is another story.

english/technics/tips/page-forwarding.txt · Last modified: 2018/06/03 18:09 (external edit)
www.planmatrix.de www.chimeric.de Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0