Jump to content

Why wont this PHP redirect script work for me on my site?

- - - - -

  • Please log in to reply
11 replies to this topic

#1
onething

onething

    Programmer

  • Members
  • PipPipPipPip
  • 118 posts
Sorry for taking you all through my daily frustrations, but this one just takes the cake. Following my failure to get a script called mydomain.com/index.php to be on mydomain.com, I decided Id redirect my home page to the page of my script, which is an okayish alternative for now, though not as good as something i thought would be so easy, the possibility of having a script on a homepage, the possibility that the creator of the script might have deemed it for us mortals to provide documentation.

So I find this site


So I apply the code it tells me to, erasing everything else from my home page:

<?php


   header( 'Location: http://mydomain.com/index.php' ) ;


?>


And Im absolutely amazed that it wont redirect. I was expecting this from Mozilla, which just seems stuck with the first time it ever sees a webpage for some stupid reason. But Explorer pretty much reliably shows up any changes in a sites script instantly, and its quite simply not redirecting, which is extremely frustrating for me. :mad:

What am i doing wrong guys?

#2
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,254 posts
  • Location:C:\Countries\US
Are you sure there's no other output before the header() call?

#3
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
Please check the PHP forum's FAQ sheet, there is an entry to check if you have sent headers after content. IE should not have to worry about incorrect code (it is not meant as a proper conforming internet browser.)

The software you are using likely is defective if you are running in to this problem.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#4
Epatron

Epatron

    Learning Programmer

  • Members
  • PipPipPip
  • 56 posts
Do you have a domain, or are you using eg. XAMPP and http://localhost/?
If you are using a http://localhost/ try to put
<?php 


   header( 'Location: YOURFILENAME.php' ) ; 


?>

EDIT: Try that too even if you have a domain.

#5
onething

onething

    Programmer

  • Members
  • PipPipPipPip
  • 118 posts

Alexander said:

Please check the PHP forum's FAQ sheet, there is an entry to check if you have sent headers after content. IE should not have to worry about incorrect code (it is not meant as a proper conforming internet browser.)

The software you are using likely is defective if you are running in to this problem.

After seeing the FAQ, I believe what you meant was to write an index.html like this:

<?php


   header( 'Location: http://mydomain.com/index.php' ) ;



if(headers_sent($file, $line) == true) {

  print "Headers are already sent by $file on $line\n";

}  

?>

I did it first in dreamweaver. Didnt work. Tried it in notepad and saved it in utf-8 like the FAQ says. But no luck. Both in Mozilla and IE8 Im just getting a blank page.

Am i doing something wrong?

#6
Epatron

Epatron

    Learning Programmer

  • Members
  • PipPipPip
  • 56 posts
Have you tested that does PHP codes show at the page?
<?php

echo "Hello world!";

?>
Test that, if you get Hello world, I don't know whats wrong but if you dont get that text try to re-save index.php like this:
1. Open WordPad
2. Name it index.php ( Yes same file name )
3. Use "Text-file" < trust me :3
4. Save (Do you wanna replace it? Answer YES!)
5. Try codes again!

I really hope that works!

#7
onething

onething

    Programmer

  • Members
  • PipPipPipPip
  • 118 posts

Epatron said:

Have you tested that does PHP codes show at the page?
<?php

echo "Hello world!";

?>
Test that, if you get Hello world, I don't know whats wrong but if you dont get that text try to re-save index.php like this:
1. Open WordPad
2. Name it index.php ( Yes same file name )
3. Use "Text-file" < trust me :3
4. Save (Do you wanna replace it? Answer YES!)
5. Try codes again!

I really hope that works!

Wow, well im not even getting Hello World, just a blank page.

The problem may be this:

I have a script thats based in index.php. Theres another script that refers to index.php, and all of this came as a result of me trying to get index.php to be my main domain page. So when I typed in mydomain.com i would get the script. But I had to type in mydomain.com/index.php

I failed at getting the index.php to be my domainpage for some annoying reason as i wrote elsewhere, so i thought maybe get my domain page to redirect to mydomain.com/index.php.

Right now the problem may be im technically trying to redirect from an index.html on the same folder (my domains folder) to an index.php. Maybe mydomain.com/ doesnt know where to go, oh i dunno this is sooo frustrating man

---------- Post added at 01:55 PM ---------- Previous post was at 01:53 PM ----------

Epatron said:

Have you tested that does PHP codes show at the page?
<?php

echo "Hello world!";

?>
Test that, if you get Hello world, I don't know whats wrong but if you dont get that text try to re-save index.php like this:
1. Open WordPad
2. Name it index.php ( Yes same file name )
3. Use "Text-file" < trust me :3
4. Save (Do you wanna replace it? Answer YES!)
5. Try codes again!

I really hope that works!

Arent we never supposed to open wordpad when editing php, html and other codes because it modifies the character encoding, like microsoft word and unlike notepad?

Also are you aware im trying to redirect from the index.html to the index.php?

#8
Epatron

Epatron

    Learning Programmer

  • Members
  • PipPipPip
  • 56 posts
I have been used WordPad now I'm using my free website hosting site's own editor..
Wordpad worked for me, so did you try to re-save the file and run the Hello World code again?

#9
onething

onething

    Programmer

  • Members
  • PipPipPipPip
  • 118 posts

Epatron said:

I have been used WordPad now I'm using my free website hosting site's own editor..
Wordpad worked for me, so did you try to re-save the file and run the Hello World code again?

Yes im getting hello world.

However its eaten up precisely the page i wanted to show, which was on index.php ^^

i want to redirect from the domain to an index.php with my script!

#10
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,254 posts
  • Location:C:\Countries\US
If you're redirecting from index.html to index.php, why not just take index.html out, would it load index.php?

If not, then you can just insert this script to the index.html page:
<script type="text/javascript"> 

  location= "index.php"; 

</script> 
That should redirect the browser to index.php, if JavaScript is on.

#11
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
The blank page is also in my FAQ, there is likely an error in the error log of which explains why your page is not showing.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#12
onething

onething

    Programmer

  • Members
  • PipPipPipPip
  • 118 posts

RhetoricalRuvim said:

If you're redirecting from index.html to index.php, why not just take index.html out, would it load index.php?

If not, then you can just insert this script to the index.html page:
<script type="text/javascript"> 

  location= "index.php"; 

</script> 
That should redirect the browser to index.php, if JavaScript is on.

Thanks.

Indeed, a few hours before you posted this i put my hands to my head and realised index.html is incompatible with index.php. latter serves me right on its own, of course, unless its the reason im having ssl issues now, though i doubt that.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users