HTML to PHP change - how to handle redirects

  • hgruber
  • Beginner
  • Beginner
  • User avatar
  • Posts: 58
  • Loc: Vero Beach Florida

Post 3+ Months Ago

Hello all,
I am wondering if there is someone who can help me with handling redirects on my site.
I am changing the format from HTML to PHP.

Thanks for reading,

peace,

haans :)
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Carnix
  • Guru
  • Guru
  • User avatar
  • Posts: 1098

Post 3+ Months Ago

What do you mean "redirects?"

Are you asking how in PHP to do the same thing that the meta Refresh tag does in HTML?

HTML:
Code: [ Select ]
<meta http-equiv="Refresh" content="10;url=http://www.domain.com/">


PHP:
PHP Code: [ Select ]
 
<? header("location: <!-- m --><span class="postlink">http://www.domain.com/</span><!-- m -->"); ?>
 
 
  1.  
  2. <? header("location: <!-- m --><span class="postlink">http://www.domain.com/</span><!-- m -->"); ?>
  3.  
  4.  


However, remember, you cannot send headers to the client after you've started sending page content. Either way, this method is always better than using the HTML tag, since it reduces talk-time between the client and the server.

Does answer you question?

.c
  • hgruber
  • Beginner
  • Beginner
  • User avatar
  • Posts: 58
  • Loc: Vero Beach Florida

Post 3+ Months Ago

Actually, I want to redirect requests for the OldFile.HTML file to the NewFile.PHP automatically.
Or, at least display the link to the new location with a message advising that the previous HTML content has been permanently removed. :?
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

The code Carnix provided above is what you want, i.e.:

Code: [ Select ]
<meta http-equiv="Refresh" content="10;url=http://www.domain.com/NewFile.php">


The ten is a variable and indicates the number of seconds before the page refreshes. You can change that to whatever you'd like. If you want it to be instantaneous make it zero.
  • Carnix
  • Guru
  • Guru
  • User avatar
  • Posts: 1098

Post 3+ Months Ago

Well you could use the HTML meta refresh tag I listed above to do just that. Just set the time to 0 instead of 10. Or you could use the mod_rewrite, perhaps

Here's another topic that has solid info on that:

http://www.ozzu.com/sutra62694.html

.c
  • hgruber
  • Beginner
  • Beginner
  • User avatar
  • Posts: 58
  • Loc: Vero Beach Florida

Post 3+ Months Ago

Okay if I am understanding this correctly.

I just insert the meta tag into the new index.php document.
When the old index.html file is requested it auto refreshes.
Loads the new index.php in it's place?

That simple eh?
So each of 500 pages one by one?

Or, is there some way to mass alter the meta tags?
I suppose not since each meta tag contains each documents name on an individual basis
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

No you insert it into the old file, not the new one. Given the number of pages you're talking about, you might want to check that mod rewrite link Carnix posted above.
  • Carnix
  • Guru
  • Guru
  • User avatar
  • Posts: 1098

Post 3+ Months Ago

You could probably also write a command line perl script to run through every file, find the <head> tag, add a newline, drop in the meta tag and another newline for any file with .html in the filename. Although, doing it by hand may be faster if you don't know Perl very well. I tend to go the route of writing the script and chalk it up to learning... but that's just me. Beware, directory recursion is a pain... but if you don't have very many directories to deal with, you could just write the script to only run on the current directory, and just move the script from directory to directory and run it each time.. I've don't something very similar dealing with adding title tags to every web file. I tried to find the script I used, but couldn't... it was really short, like 10 lines or something.

.c
  • Axe
  • Genius
  • Genius
  • User avatar
  • Posts: 5739
  • Loc: Sub-level 28

Post 3+ Months Ago

You could also just setup your 301 redirects in a .htaccess.
  • hgruber
  • Beginner
  • Beginner
  • User avatar
  • Posts: 58
  • Loc: Vero Beach Florida

Post 3+ Months Ago

I have dabbled with some cgi scripting on scripts I downloaded.
But, that's the extent of my perl.
I did what I had to do to make the script work on my server.
Which as you probably know comes with instructions.
Not very accurate one's at that!

If you could locate the script it would at least give me something to go by.
A pattern to replicate/alter to my own needs.

I sure would appreciate it if you would try to locate it for me.

In the mean time I will visit the link you posted for me.

peace 8)

and Thanx :idea:
  • hgruber
  • Beginner
  • Beginner
  • User avatar
  • Posts: 58
  • Loc: Vero Beach Florida

Post 3+ Months Ago

Now, I was reading about the 301 redirects in the .htaccess file
But, there were some things I didn't quite understand with that.
It's probably not beyond the scope of my capabilities.
And sounds preferable to altering HTML code all day long and then some with 500+ pages to switch.

The other question I had was, I just drop the meta tag code into a file named as the old "filename.html" with the only line being the new meta tag in the old document?

or since it's a meta tag it doesn't matter if the original html remains within the doc because the meta tag is going to redirect it anyway.

So, theoretically I could make a line of code <meta tag> and drop it into a new empty html doc and delete all the original html documents. So long as the filename matched the old html filename.

Anyone be willing to offer guidance in the .htaccess file arena?
sonds more complex but, one files verses 500+.

Now that sounds more like where I want to be.

peace 8)
  • Carnix
  • Guru
  • Guru
  • User avatar
  • Posts: 1098

Post 3+ Months Ago

hgruber wrote:
So, theoretically I could make a line of code <meta tag> and drop it into a new empty html doc and delete all the original html documents. So long as the filename matched the old html filename.


Yes, you could do that. Just for the sake of correctness, though, do:

Code: [ Select ]
<html>
<meta ...>
</html>
  1. <html>
  2. <meta ...>
  3. </html>


If you want to add DOCTYPE and all that, to be even MORE correct... it wouldn't hurt. Nevertheless, you're still going to have to create the meta tag custom for each page regardless of whether you're open the existing and pasting the tag, or creating a new file and overwriting the old one....

htaccess will probably be easier... although... I'd ask whether it's actually necessary to redirect all files. Is this site extensively linked to from other sites or bookmarked? If so, which pages? All of them? If might reduce the work to only redirect pages that really need to be redirected, and just convert the rest to PHP with a custom error page that explains that the site has been converted... etc. You could probably even use that page to give them a link to the new PHP file (take the requested, but not found file and use PHP or CGI or something to replace the .html with .php and present that as a link on the error page...)

.c
  • hgruber
  • Beginner
  • Beginner
  • User avatar
  • Posts: 58
  • Loc: Vero Beach Florida

Post 3+ Months Ago

some of the pages are posted as Legal Documents & Legal Public Notices
So, it is essential these are re/located on say a google search or when anything like that is done.

Actually this is my biggest concern.

I am thinking I am just going to change everything to PHP and let it ride, let the chips fall where they may.
  • hgruber
  • Beginner
  • Beginner
  • User avatar
  • Posts: 58
  • Loc: Vero Beach Florida

Post 3+ Months Ago

[quote="Carnix"][quote="hgruber"]


Yes, you could do that. Just for the sake of correctness, though, do:

Code: [ Select ]
<html>
<meta ...>
</html>
  1. <html>
  2. <meta ...>
  3. </html>


If you want to add DOCTYPE and all that, to be even MORE correct... it wouldn't hurt. Nevertheless, you're still going to have to create the meta tag custom for each page regardless of whether you're open the existing and pasting the tag, or creating a new file and overwriting the old one....
=======================
=======================

I was thinking just use a blank dreamweaver html file and insert the proper filenames into each meta tag for the individual documents I absolutely need to be redirected.

For instance, the Legal Docs & Public Notices I mentioned.

peace 8)
  • hgruber
  • Beginner
  • Beginner
  • User avatar
  • Posts: 58
  • Loc: Vero Beach Florida

Post 3+ Months Ago

okay I added the meta tag to the index.html and it worked.

But, I added code for index2.html, and index3.html and they were redirected to index.php.

I am guessing this redirect just refreshes the directory and opens the index.php file rather than pointing it to the new index2.php, index3.php file.
  • Carnix
  • Guru
  • Guru
  • User avatar
  • Posts: 1098

Post 3+ Months Ago

You have to put change the tag based on the file you want to redirect to...


in index2.html:

Code: [ Select ]
<meta http-equiv="Refresh" content="10;url=http://www.domain.com/index2.php">


And so forth.

There's also a JavaScript method that might work... though it wouldn't require end users to have Javascript... it would, however be more dynamic.


You can get the location of the current window, use a regex to switch the .html to .php, then location.replace(); using the modified URL... Again, it would require JS to be enabled on the client.

.c
  • hgruber
  • Beginner
  • Beginner
  • User avatar
  • Posts: 58
  • Loc: Vero Beach Florida

Post 3+ Months Ago

Yes, I thought I had done that.

But, I looked back into the code and saw I had not.
I merely copied and pasted the meta tag from the first index.html and forgot to edit it.

My fault!!!
Doh!!!

Thanks again,

peace 8)
  • hgruber
  • Beginner
  • Beginner
  • User avatar
  • Posts: 58
  • Loc: Vero Beach Florida

Post 3+ Months Ago

now, I have a mirror I am setting up.

obviously the <meta http-equiv="Refresh" content="10;url=http://www.domain.com/index2.php"> won't work for that machine as with directory structure there can I just add the filename thus <meta http-equiv="Refresh" content="10;url=index2.php">
  • Carnix
  • Guru
  • Guru
  • User avatar
  • Posts: 1098

Post 3+ Months Ago

Yes, you don't need to specify the domain.
Again, though, I would remove the 10, which means the redirect will wait 10 seconds and replace it with 0, which will tell the browser to redirect as fast as possible. (nearly instantly, once a page has been cached, since the browser will remember the redirect on it's own.. at least, IE does anyway).
.c
  • hgruber
  • Beginner
  • Beginner
  • User avatar
  • Posts: 58
  • Loc: Vero Beach Florida

Post 3+ Months Ago

Yep, I'm all over it boss!
I tried it and it happened!
Some of the pages I already did copy and paste got the 10 second refresh. But, I caught it and made them "0" seconds from now on.

That and the important pages.

Thanx again for all you guys help.

it's a lot of work.
But, It has to be done!

peace 8)

Post Information

  • Total Posts in this topic: 20 posts
  • Users browsing this forum: No registered users and 133 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.