Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

Post Timeline

edited body
Source Link
Abdur Rehman
  • 3.3k
  • 5
  • 35
  • 50

To redirect the visitor to another page (particularly useful in a conditional loop), simply use the following code:

<?php
 header('Location: mypage.php');
?>

In this case, mypage.php is the address of the page to which you would like to redirect the visitors. This address can be absolute and may also include the parameters in this format: mypage.php?param1=val1¶m2=val2param1=val1&m2=val2)

Relative/Absolute Path

When dealing with relative or absolute paths, it is ideal to choose an absolute path from the root of the server (DOCUMENT_ROOT). Use the following format:

<?php
 header('Location: /directory/mypage.php');
?>

If ever the target page is on another server, you include the full URL:

<?php
 header('Location: http://www.ccm.net/forum/');
?>

HTTP Headers

According to HTTP protocol, HTTP headers must be sent before any type of content. This means that no characters should ever be sent before the header — not even an empty space!

Temporary/Permanent Redirections

By default, the type of redirection presented above is a temporary one. This means that search engines, such as Google Search, will not take the redirection into account when indexing.

If you would like to notify search engines that a page has been permanently moved to another location, use the following code:

<?
 header('Status: 301 Moved Permanently', false, 301);
 header('Location: new_address');
?>

For example, this page has the following code:

<?
 header('Status: 301 Moved Permanently', false, 301);
 header('Location: /pc/imprimante.php3');
 exit();
?>

When you click on the link above, you are automatically redirected to this page. Moreover, it is a permanent redirection (Status: 301 Moved Permanently). So, if you type the first URL into Google, you will automatically be redirected to the second, redirected link.

Interpretation of PHP Code

The PHP code located after the header() will be interpreted by the server, even if the visitor moves to the address specified in the redirection. In most cases, this means that you need a method to follow the header() function of the exit() function in order to decrease the load of the server:

<?
 header('Status: 301 Moved Permanently', false, 301);
 header('Location: address');
 exit();
?>

To redirect the visitor to another page (particularly useful in a conditional loop), simply use the following code:

<?php
 header('Location: mypage.php');
?>

In this case, mypage.php is the address of the page to which you would like to redirect the visitors. This address can be absolute and may also include the parameters in this format: mypage.php?param1=val1¶m2=val2)

Relative/Absolute Path

When dealing with relative or absolute paths, it is ideal to choose an absolute path from the root of the server (DOCUMENT_ROOT). Use the following format:

<?php
 header('Location: /directory/mypage.php');
?>

If ever the target page is on another server, you include the full URL:

<?php
 header('Location: http://www.ccm.net/forum/');
?>

HTTP Headers

According to HTTP protocol, HTTP headers must be sent before any type of content. This means that no characters should ever be sent before the header — not even an empty space!

Temporary/Permanent Redirections

By default, the type of redirection presented above is a temporary one. This means that search engines, such as Google Search, will not take the redirection into account when indexing.

If you would like to notify search engines that a page has been permanently moved to another location, use the following code:

<?
 header('Status: 301 Moved Permanently', false, 301);
 header('Location: new_address');
?>

For example, this page has the following code:

<?
 header('Status: 301 Moved Permanently', false, 301);
 header('Location: /pc/imprimante.php3');
 exit();
?>

When you click on the link above, you are automatically redirected to this page. Moreover, it is a permanent redirection (Status: 301 Moved Permanently). So, if you type the first URL into Google, you will automatically be redirected to the second, redirected link.

Interpretation of PHP Code

The PHP code located after the header() will be interpreted by the server, even if the visitor moves to the address specified in the redirection. In most cases, this means that you need a method to follow the header() function of the exit() function in order to decrease the load of the server:

<?
 header('Status: 301 Moved Permanently', false, 301);
 header('Location: address');
 exit();
?>

To redirect the visitor to another page (particularly useful in a conditional loop), simply use the following code:

<?php
 header('Location: mypage.php');
?>

In this case, mypage.php is the address of the page to which you would like to redirect the visitors. This address can be absolute and may also include the parameters in this format: mypage.php?param1=val1&m2=val2)

Relative/Absolute Path

When dealing with relative or absolute paths, it is ideal to choose an absolute path from the root of the server (DOCUMENT_ROOT). Use the following format:

<?php
 header('Location: /directory/mypage.php');
?>

If ever the target page is on another server, you include the full URL:

<?php
 header('Location: http://www.ccm.net/forum/');
?>

HTTP Headers

According to HTTP protocol, HTTP headers must be sent before any type of content. This means that no characters should ever be sent before the header — not even an empty space!

Temporary/Permanent Redirections

By default, the type of redirection presented above is a temporary one. This means that search engines, such as Google Search, will not take the redirection into account when indexing.

If you would like to notify search engines that a page has been permanently moved to another location, use the following code:

<?
 header('Status: 301 Moved Permanently', false, 301);
 header('Location: new_address');
?>

For example, this page has the following code:

<?
 header('Status: 301 Moved Permanently', false, 301);
 header('Location: /pc/imprimante.php3');
 exit();
?>

When you click on the link above, you are automatically redirected to this page. Moreover, it is a permanent redirection (Status: 301 Moved Permanently). So, if you type the first URL into Google, you will automatically be redirected to the second, redirected link.

Interpretation of PHP Code

The PHP code located after the header() will be interpreted by the server, even if the visitor moves to the address specified in the redirection. In most cases, this means that you need a method to follow the header() function of the exit() function in order to decrease the load of the server:

<?
 header('Status: 301 Moved Permanently', false, 301);
 header('Location: address');
 exit();
?>
Active reading.
Source Link
Peter Mortensen
  • 31.3k
  • 22
  • 110
  • 134

To redirect the visitor to another page (particularly useful in a conditional loop), simply use the following code:

<?php
header('Location: mypage.php');
?>

In this case, mypage.php is the address of the page to which you would like to redirect the visitors. This address can be absolute and may also include the parameters in this format: mypage.php?param1=val1¶m2=val2)

Relative/Absolute Path

When dealing with relative or absolute paths, it is ideal to choose an absolute path from the root of the server (DOCUMENT_ROOT). Use the following format:

<?php
header('Location: /directory/mypage.php');
?>

If ever the target page is on another server, you include the full URL:

<?php
header('Location: http://www.ccm.net/forum/');
?>

HTTP Headers

According to HTTP protocol, HTTP headers must be sent before any type of content. This means that no characters should ever be sent before the header — not even an empty space!

Temporary/Permanent Redirections

By default, the type of redirection presented above is a temporary one. This means that search engines, such as Google Search, will not take the redirection into account when indexing.

If you would like to notify search engines that a page has been permanently moved to another location, use the following code:

<?
header('Status: 301 Moved Permanently', false, 301);
header('Location: new_address');
?>

For example, this page has the following code:

<?
header('Status: 301 Moved Permanently', false, 301);
header('Location: /pc/imprimante.php3');
exit();
?>

When you click on the link above, you are automatically redirected to this page. Moreover, it is a permanent redirection (Status: 301 Moved Permanently). So, if you type the first URL into Google, you will automatically be redirected to the second, redirected link.

Interpretation of PHP Code

The PHP code located after the header() will be interpreted by the server, even if the visitor moves to the address specified in the redirection. In most cases, this means that you need a method to follow the header() function of the exit() function in order to decrease the load of the server:

<?
header('Status: 301 Moved Permanently', false, 301);
header('Location: address');
exit();
?>

To redirect the visitor to another page (particularly useful in a conditional loop), simply use the following code:

<?php
header('Location: mypage.php');
?>

In this case, mypage.php is the address of the page to which you would like to redirect the visitors. This address can be absolute and may also include the parameters in this format: mypage.php?param1=val1¶m2=val2)

Relative/Absolute Path

When dealing with relative or absolute paths, it is ideal to choose an absolute path from the root of the server (DOCUMENT_ROOT). Use the following format:

<?php
header('Location: /directory/mypage.php');
?>

If ever the target page is on another server, you include the full URL:

<?php
header('Location: http://www.ccm.net/forum/');
?>

HTTP Headers

According to HTTP protocol, HTTP headers must be sent before any type of content. This means that no characters should ever be sent before the header — not even an empty space!

Temporary/Permanent Redirections

By default, the type of redirection presented above is a temporary one. This means that search engines, such as Google, will not take the redirection into account when indexing.

If you would like to notify search engines that a page has been permanently moved to another location, use the following code:

<?
header('Status: 301 Moved Permanently', false, 301);
header('Location: new_address');
?>

For example, this page has the following code:

<?
header('Status: 301 Moved Permanently', false, 301);
header('Location: /pc/imprimante.php3');
exit();
?>

When you click on the link above, you are automatically redirected to this page. Moreover, it is a permanent redirection (Status: 301 Moved Permanently). So, if you type the first URL into Google, you will automatically be redirected to the second, redirected link.

Interpretation of PHP Code

The PHP code located after the header() will be interpreted by the server, even if the visitor moves to the address specified in the redirection. In most cases, this means that you need a method to follow the header() function of the exit() function in order to decrease the load of the server:

<?
header('Status: 301 Moved Permanently', false, 301);
header('Location: address');
exit();
?>

To redirect the visitor to another page (particularly useful in a conditional loop), simply use the following code:

<?php
header('Location: mypage.php');
?>

In this case, mypage.php is the address of the page to which you would like to redirect the visitors. This address can be absolute and may also include the parameters in this format: mypage.php?param1=val1¶m2=val2)

Relative/Absolute Path

When dealing with relative or absolute paths, it is ideal to choose an absolute path from the root of the server (DOCUMENT_ROOT). Use the following format:

<?php
header('Location: /directory/mypage.php');
?>

If ever the target page is on another server, you include the full URL:

<?php
header('Location: http://www.ccm.net/forum/');
?>

HTTP Headers

According to HTTP protocol, HTTP headers must be sent before any type of content. This means that no characters should ever be sent before the header — not even an empty space!

Temporary/Permanent Redirections

By default, the type of redirection presented above is a temporary one. This means that search engines, such as Google Search, will not take the redirection into account when indexing.

If you would like to notify search engines that a page has been permanently moved to another location, use the following code:

<?
header('Status: 301 Moved Permanently', false, 301);
header('Location: new_address');
?>

For example, this page has the following code:

<?
header('Status: 301 Moved Permanently', false, 301);
header('Location: /pc/imprimante.php3');
exit();
?>

When you click on the link above, you are automatically redirected to this page. Moreover, it is a permanent redirection (Status: 301 Moved Permanently). So, if you type the first URL into Google, you will automatically be redirected to the second, redirected link.

Interpretation of PHP Code

The PHP code located after the header() will be interpreted by the server, even if the visitor moves to the address specified in the redirection. In most cases, this means that you need a method to follow the header() function of the exit() function in order to decrease the load of the server:

<?
header('Status: 301 Moved Permanently', false, 301);
header('Location: address');
exit();
?>
Source Link
Abdur Rehman
  • 3.3k
  • 5
  • 35
  • 50

To redirect the visitor to another page (particularly useful in a conditional loop), simply use the following code:

<?php 
header('Location: mypage.php'); 
?>

In this case, mypage.php is the address of the page to which you would like to redirect the visitors. This address can be absolute and may also include the parameters in this format: mypage.php?param1=val1¶m2=val2)

Relative/Absolute Path

When dealing with relative or absolute paths, it is ideal to choose an absolute path from the root of the server (DOCUMENT_ROOT). Use the following format:

<?php 
header('Location: /directory/mypage.php'); 
?>

If ever the target page is on another server, you include the full URL:

<?php 
header('Location: http://www.ccm.net/forum/'); 
?> 

HTTP Headers

According to HTTP protocol, HTTP headers must be sent before any type of content. This means that no characters should ever be sent before the header — not even an empty space!

Temporary/Permanent Redirections

By default, the type of redirection presented above is a temporary one. This means that search engines, such as Google, will not take the redirection into account when indexing.

If you would like to notify search engines that a page has been permanently moved to another location, use the following code:

<? 
header('Status: 301 Moved Permanently', false, 301); 
header('Location: new_address'); 
?>

For example, this page has the following code:

<? 
header('Status: 301 Moved Permanently', false, 301); 
header('Location: /pc/imprimante.php3'); 
exit(); 
?>

When you click on the link above, you are automatically redirected to this page. Moreover, it is a permanent redirection (Status: 301 Moved Permanently). So, if you type the first URL into Google, you will automatically be redirected to the second, redirected link.

Interpretation of PHP Code

The PHP code located after the header() will be interpreted by the server, even if the visitor moves to the address specified in the redirection. In most cases, this means that you need a method to follow the header() function of the exit() function in order to decrease the load of the server:

<? 
header('Status: 301 Moved Permanently', false, 301); 
header('Location: address'); 
exit(); 
?>
lang-php

AltStyle によって変換されたページ (->オリジナル) /