Page forwarding (redirect)

Example: The page will be redirected to a subdirectory.

Adoption: phpwcms is located in the subdirectory

Standard entries in the

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

Solution 1:

RewriteEngine on
RewriteRule ^(.*) [R,L]

Solution 2:

header("HTTP/1.1 301 Moved Permanently");

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).

Docu: –
Forum: mod_rewrite + RewriteRule + errorDocument

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

Tag: –
fileiname: –
Folder: –


  • $phpwcms['allow_ext_render'] = 1;

Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location:" );

Forwarding with error 404 (second try):

Another attempt for dealing with “not found” or “moved elswhere”. See forum:

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" "">
<html xmlns="">
<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;
    overflow: hidden;
#main {
    background-color: transparent;
    padding: 0.7em;
    border: 0.3em dashed #b9821a;
    margin: -16.5em 0 0 -25em;
    top: 50%;
    left: 50%;
    width: 50em;
    height: 33em;
    font-family: "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
h2 {
h4 {
a {
hr {
    color: #EEEEEE;
    background-color: #EEEEEE;
#form {
    border:0.2em solid #ff0000;
    margin:0 auto;
#form .input {
    border:0.2em solid #ffffff;
#form .submit {
    border:0.2em solid #ffffff;
<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:/','http:///www.myothersuperdom.tld1/','http://www.anothersupertotal.tld2';
<script type="text/javascript"

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/

// 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" );
if($aktion[0] == 0 && !isset($_GET['adclickval'])) {
switch ($_SERVER["SERVER_NAME"]) {
case 'mysupidupidomain.tld':
            header( "HTTP/1.1 301 Moved Permanently" );
default:header( "HTTP/1.1 301 Moved Permanently" );

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) 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