Can i redirect pages automatically?

tlife143

New Member
Messages
2
Reaction score
0
Points
0
I WANT TO REDIRECT WEB PAGES AUTOMATICALLY!!! CAN I DO???

I USED THIS CODE TO REDIRECT
<?PHP
header('Location: http://redirectpage.html')
?>

but it is displaying an error message as

Warning: Cannot modify header information - headers already sent


plz help me out!!!
 

f1lt3rh34d

New Member
Messages
30
Reaction score
0
Points
0
that's because you already sent data to the browser.

There's also an alternative which doesn't require PHP.

Code:
<?php
echo '<meta http-equiv=refresh content="1; url=http://redirectpage.html">';
?>

The 1 is the delay; currently 1 second. You can also set it to 0.
url is the location where it should redirect to.
 

lhyman

New Member
Messages
198
Reaction score
0
Points
0
that's because you already sent data to the browser.

There's also an alternative which doesn't require PHP.

Code:
<?php
echo '<meta http-equiv=refresh content="1; url=http://redirectpage.html">';
?>

The 1 is the delay; currently 1 second. You can also set it to 0.
url is the location where it should redirect to.

Thanks, that one worked for me !
 

subsilver

New Member
Messages
5
Reaction score
0
Points
0
There is also one method which can be used if the website is hosted on apache webserver (x10hosting uses apache). Edit .htaccess file in your site root directory, and add following line:
Code:
Redirect 301 /oldpage.html http://www.example.com/newpage.html
Cheers!
 

marshian

New Member
Messages
526
Reaction score
9
Points
0
Just use headers the way they're supposed to be used, before any other output.
PHP:
<?PHP
header('Location: http://redirectpage.html')
?>
Will work perfectly, if you make sure there is NO OUTPUT BEFORE THE HEADER. A newline character or space before the <?php does count as output too.
 

drf1229

New Member
Messages
71
Reaction score
1
Points
0
<script type="text/javascript">
window.location="http://redirectpage.html";
</script>
 

xav0989

Community Public Relation
Community Support
Messages
4,467
Reaction score
95
Points
0
I believe that <?PHP should be in fact <?php (I might be wrong, but it helps not to use caps if not needed)

Also, you should avoid using only client-based redirection, since it can easily be bypassed. JavaScript should also be the last one you use since search engines don't use JavaScript and it can be disabled in normal browsers. The order of redirection should be like this:

  1. Server-side redirection (PHP, Perl, htaccess [apache], SSI, etc.)
  2. Meta based redirection
  3. JavaScript Redirection
  4. Link based redirection

I can provide a script implementing all these in order if you need.
 
Top