Redirecting All Htm Files To Php Site...

free web hosting
Free Web Hosting > Computers & Tech > Designing > Web Design and HTML

Redirecting All Htm Files To Php Site...

WeaponX
Hi, just finished converting all my files from .HTM to .PHP files. Is there an easy way to redirect all my users who go to the .HTM pages to the .PHP pages instead? Basically all the names remained the same. Just the extension changed.

My webhost has cPanel 10. something...

Thanks.

Reply

miCRoSCoPiC^eaRthLinG
Include a short redirection code in your HTM file --> PHP file.
Here's a tiny redirection script that in conjuction with the setTimeOut command waits for that many seconds before redirecting to the new page.Include this in the HEAD of your page.
CODE

<script type="text/javascript">

function delayer(){

 document.location = "http://www.domain.com/abcd.php"
}

</script>


Replace location with your own domain+page.

In the <BODY> tag, put this code:
CODE

<body onload="setTimeout('delayer()', xxxx)">


This will cause the setTimeout function to wait for xxxx milliseconds and then call the delayer function, which in turn loads your new page. Or you could bypass the setTimeout alltogether - and use the delayer function rightaway with onload. Will work all the same.

 

 

 


Reply

WeaponX
Thanks m^e,

Just reread what I put in the title and message...I should have been more clear. Sorry...

I don't have the .HTM files anymore but if someone goes to one of them, it's a Page not found message. I want a way to redirect them to the .PHP page if this can be done.


Reply

vujsa
What you want to do is use mod rewrite.

Basically, here is what mod rewrite will do:
User types in www.whatever.com/mypage1.html the server takes that request and coverts the url to www.whatever.com/mypage1.php. Then the requested php page is served.

You'll need to create or edit yout .htaccess file in your /public_html directory.

CODE

#  mod_rewrite in use
RewriteEngine On

RewriteRule ^mypage1\.html$ mypage1.php


Now you could simply forward all html file requests to the index like so:
CODE

RewriteRule ^(.*)\.html$ index.php


For more advanced php style mod rewrites, here is what to do:
CODE

RewriteRule ^mypage2\.html(.*)$ index.php?act=mypage2$1
/mypage2.html?&section=section1 would point to /index.php?act=mypage2&section=section1

Now you may notice the (.*) right after the .html, this means everything at that location of the url. So if you were doing a lot of mod rewrites and you missed something, your link wouldn't be broken. Whatever in located in the position of the (.*) will be inserted at the end where you see the $1. You can place a more specific rule in the () if you prefer. You can also use the command multiple times like so:
CODE

RewriteRule ^/(.*)mypage2\.html(.*)$ index.php?act=mypage2&section=$1$2
/section1_mypage2.html would point to /index.php?act=mypage2&section=section1

I think you'll need to let us know what rules you need help with. I don't know what your drirectory looked like before or after your changeover.

I hope this helps. cool.gif

vujsa

Reply

WeaponX
Thanks vujsa...for that script though, is there any way to redirect it to the same/respective PHP page? I don't want all of them to go to index.php but to go to their own PHP file.

Reply

vujsa
This should do what you want:
CODE


#  mod_rewrite in use

RewriteEngine On

RewriteRule ^(.*)\.html$ $1.php
RewriteRule ^(.*)\.htm$ $1.php


It'll take any file.html and return file.php instead. No matter what the name of the HTML file is, the server will return the equivalent PHP file. Note that I have a rule here fore both .html and .htm, the .html rule should com first since .html contains .htm. If you put the .htm first, then the server could change your file.html to file.phpl. See how that works? If you don't understand that part be sure to ask, it is very important. The rewrite engine picks the first match even if there is a better rule after it.

If you have other rewrite rules to include, be sure to put them above this rule since this rule is the most general. It is usually used as the default setting.. If the file doesn't match any specific rule, then just change the file extention to .php from .html.

I would also check your error logs and find out which links may be dead on your site. Pages removed, pages renamed, etc... Then write specific rules for your dead links to be rewritten as index.php. The specific rules should always come before the general rule.

So here would be a better .htaccess file for you:
CODE

#  mod_rewrite in use

RewriteEngine On
# First we have our specific rules:
RewriteRule ^deadlink_20\.html$ index.php
RewriteRule ^deadlink_13\.html$ index.php
RewriteRule ^deadlink_1\.html$ index.php
RewriteRule ^oldlink_5\.html$ index.php
RewriteRule ^oldlink_1\.html$ index.php

# Then we have our general (default) rule:
RewriteRule ^(.*)\.html$ $1.php
RewriteRule ^(.*)\.htm$ $1.php

# We always leave a blank line at the bottom of the file.


You'll have to replace the "deadlinks" above with your own information. Notice that the deadlink and oldlink files are in reverse numeric order to prevent deadlink_13 being rewitten for the rule for deadlink_1. It is that same issue as above where rewrite looks for the first match, not the best match!

You should leave a blank line at the bottom of the file so that cPanel has a place to insert commands if need be.

I don't remember for sure if this rule will effect all subdirectories or not so you'll need to do some testing and checking.

Good Luck. cool.gif

vujsa

Reply

Quatrux
be careful using .htaccess files, because using them, googlebot might get an 406 error page, you would not want that right ? do like vujsa told you, but keep in mind to set:

Options -Multiviews
RewriteEngine On..
...

Because it seems that, I can't remember on what apache version, using multiviews, googlebot gets an 406 error and you might not get indexed in google, that is one of the worst things to happen for a website. wink.gif

Reply

vujsa
I've given this some thought and decided that you could also use url redirects in your .htaccess instead of mod rewrite:

The upside to mod rewrite is that the user never knows that the page has moved. the page still appears to be whatever.html!

But that means that you could end up generating more and more links to the .html pages by users bookmarking the page with the outdated url.

If you use a redirect rule instead, you could then display the actual new url. It works much the same way as modrewite:
CODE

RedirectMatch permanent ^(.*)\.html$ $1.php


So your .htaccess file would look like this instead:
CODE

# First we have our specific rules:
RedirectMatch permanent ^deadlink_20\.html$ index.php
RedirectMatch permanent ^deadlink_13\.html$ index.php
RedirectMatch permanent ^deadlink_1\.html$ index.php
RedirectMatch permanent ^oldlink_5\.html$ index.php
RedirectMatch permanent ^oldlink_1\.html$ index.php

# Then we have our general (default) rule:
RedirectMatch permanent ^(.*)\.html$ $1.php
RedirectMatch permanent ^(.*)\.htm$ $1.php

# We always leave a blank line at the bottom of the file.



This may be a better solution for you since it would eliminate the chance of outdated urls being bookmarked or indexed.

Alternatively, you could use a combination of the two. Have the converted pages redirect to their new versions and have dead links rewrite to index.php:
CODE


#  mod_rewrite in use

RewriteEngine On
# First we have our specific rules:
RewriteRule ^deadlink_20\.html$ index.php
RewriteRule ^deadlink_13\.html$ index.php
RewriteRule ^deadlink_1\.html$ index.php
RewriteRule ^oldlink_5\.html$ index.php
RewriteRule ^oldlink_1\.html$ index.php

# Then we have our general (default) rule:
RedirectMatch permanent ^(.*)\.html$ $1.php
RedirectMatch permanent ^(.*)\.htm$ $1.php

# We always leave a blank line at the bottom of the file.


Note that I left the order the same to prevent a url being redirected before it could have been rewritten.

This would cover most of your situations and either reduce the number of requests on obsolete urls or hide the fact that some pages no longer exist by serving up your index.php instead.

I haven't had any trouble with Google indexing my site by using mod rewrite. Infact, I use mod rewrite to make it easier for the robots to index my site. Some of them get confussed by the long php query urls (index.php?action=whatever&location=whereever).

Keep in mind that using .htaccess files carries with it no dangers. The dangers come from the commands that you place in it. A bad mod rewrite rule will cripple your website. In fact while doing some testing to help answer this question, I accidentally disabled the Free Web Hosting Application Form for both AstaHost and Trap17. laugh.gif I rewrote all of my root directory PHP files as HTML files. Since I don't actually have a req_form.html file, a few members got a "404 - Page Not Found Error".

A general redirect rule like I have shown you would be just as debilitating to my website. Be sure to add rules to offset a general rule if you need to exclude something. I believe that rules are only run once on a n incoming url so if you set specific rule to redirect or rewrite to itself first, you would effectively exclude that url from the change.

Say for instance you have an HTML file that you don't want to convert and you wanted to exclude it from the rules above:
CODE

RewriteRule ^myHTMLpage\.html$ myHTMLpage.html

Since this is a very very specific rule, you should place it at the top of the file.

============================================

There is another option to all of this, we could write a PHP script that would check and see if the requested PHP file exists. If the file does exist the script will serve that file otherwise the index.php file will be served.

This would consist of a mod rewrite rule to change the .html url into a .php query url to the redirection script. The redirection script (maybe something like /redirect.php?file=mypage) would then use the file name as the basis of a check to see if a .php file of that name exists. If that file does exist, redirect to that file. If not, redirect to index.php. I would be happy to discuss this further in the apropriate forum if you are interested.

I hope this helps. cool.gif

vujsa

Reply

iGuest
On the topic above I use a

RedirectMatch 301 (.*)\.html$ http://bbbb.com$1.php

I need to exclude the directory stats - at http://bbbb.com/stats as it has html in it and the directory is locked

What code so I use to exclude only that directory form all redirects?

Thank a lot

-Alan

Reply


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Recent Queries:-
  1. php redirect all files in folder - 20.36 hr back. (1)
  2. exclude from redirectmatch - 46.11 hr back. (1)
  3. using 301 to point htm to php files in certain directory - 46.64 hr back. (1)
  4. redirect web page with drop menus using php - 109.02 hr back. (1)
  5. add a redirect to htm file - 113.29 hr back. (1)
  6. make all .html redirect to .htm - 151.87 hr back. (1)
  7. .htaccess in 406 error in wml - 168.11 hr back. (1)
  8. redirect all htm - 169.52 hr back. (1)
  9. how can i redirect all html files to htm files in mysite - 174.90 hr back. (1)
  10. mod rewrite htm acts as php - 190.78 hr back. (1)
  11. redirect .html files to .php files - 221.80 hr back. (1)
  12. redirect all html files to another site - 291.52 hr back. (1)
  13. all internet redirect to php sites - 307.38 hr back. (1)
  14. php redirect drop-down menu - 336.04 hr back. (1)
Similar Topics

Keywords : redirecting, htm, files, php, site

  1. Website Navigation Hover Buttons Stick So Made Css Today
    need further help with tutorial from this site (7)
  2. Stretching My Site Vertically
    Using CSS or HTML (6)
    I know it's possible, I've seen it one time. But I forgot. Many websites, if they hold more
    content than there is room for in the minimum height, the site stretches vertically. How can I do
    this? I only know that I need a background image of 1px height. Thanks in advance MediYama....
  3. Unicode Encoded Site - Characters Not Displaying Properly?
    (4)
    Hey guys, I've been working on a AJAX based CMS for a client for the last few days
    and am in the final stages of deployment. I've run into a slight problem here. The site is
    supposed to be in Norwegian. The back-end uses the tinyMCE editor for adding in content, which
    is stored in MySQL. Now this presents no problem at all and the content is displayed just fine in
    the browser.. Problem arises when it comes to the site menu. It is a drop-down menu script from
    DynamicDrive, which reads off the menu items the same way from MySQL as the content and b....
  4. Cvs For Maintaining Your Site
    (0)
    This is something every webmaster would love to use.. but didn't know existed. There is a tool
    named "CVS" which can be used to save all versions of your program. You initially start with a set
    of source code files, and the project grows from there on. If you make a mistake you can always
    restore the changes you made from the previous version you added to the "CVS". During a
    website's lifetime, a lot of code keeps changing, and more often than not, some code causes a
    problem in the rest of your website. Using CVS would help to detect where you slipped in those ....
  5. Need Help With Multi-lingual Site Design
    (6)
    Does any of you have any ideas on multi-lingual site design? I'm looking for some
    resources/guides that'll show me the exact technique of achieving this... I am NOT looking for
    the Google Translate kind of option, where you've got a bunch of buttons on your site - clicking
    on which, will pass your page through Google Translator producing a totally garbled grammatical
    output in another language... What I want is to define every Text Element on the site as
    variables and depending on the lanugage of your choice, these variables are filled in from
    pre-defin....
  6. Thinking About An "audio" Web Site
    Your feedback please (4)
    Our company is in the web development (and marketing) business. This winter we are re-developing
    our own site, and I have been thinking of making the web site also available as an audio option.
    Since I'm an audio learner this concept interests me, and I figured I would throw this idea to
    you guys for you opinions / feedback etc. as I don't like to act on something without first
    getting feedback from people. I have the right recording gear to make the files sound good, so
    there's no problem there. And I would still do the usual "TEXT" in particular the sea....
  7. Help Choose A New Banner For Me Please
    Help needed to choose a new banner for my site (11)
    Ok yesterday we got busy and spent some time making some new banners for The Sounds Of The Suburbs
    site. We haev can for sort of an urban decay theme on the site..and were going to totally remodel
    it this week to different feel and maybe even get the databases working /wink.gif"
    style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" /> So can you take a look at the
    images below and post which one you feel is the best one.. Your views will help us hopefully decide
    on the new banner Banner 1 Banner 2 Banner 3 Banner 4 Banner 5 Banner 6....
  8. How Do I Keep A Background On My Site
    (14)
    I had a background on my site that i got on the internet. I don't remember the name of the site
    but from it I was able to save the background (which was a textured blue background) to
    photobucket.com. I've had it there for awhile, but now, all-of-the-sudden it disappeared. I
    guess you can only keep things on photobucket for so long. But how do I keep a background on my
    site if I can't host it somewhere? Is there a way to put the picture in cPanel and use it from
    there? If there is, I cant figure it out.....
  9. With Or Without Tabs?
    help me choose design for my site. (15)
    As I run this website for more than a 1 year now, Im getting more and more visitors, I have a
    feeling that navigation on my page isn't such great as it seems on the beggining. I tried to
    navigate like first-time user, and have trouble finding information that I was looking for. So, I
    have an idea, to integrate basic types of information on 4 main TABs at the top of page. Look at
    the two pictures and tell me which one is better: the one with the tabs, or the one without.
    The above picture is new version, with tabs... The above picture is current look ....
  10. Embedding PSD Files Into Dreamweaver
    Embedding PSD files into Dreamweaver (6)
    Hi all, I am new member in this forum. I am Web Designer residing in India and made two
    websites: http://www.adknowhow.com http://www.punjabivibrations.com I am facing a probem. I
    want to make a website with Photoshop Template. But I don't know how to embed this template in
    Dreamweaver. I have full knowledge about HTML. Is anyone in this group would like to tell me about
    how to embed this template in Dreamweaver. Or Tell me any web site from where I would find solution
    about my problem. I will be very thankful for hisself or herself. Thanks in Advan....
  11. How To Display XX Users Online On Your Site ?
    (5)
    i've seen many sites around the net that have something on their page that says like 348 users
    online... does anyone here know how that is done and could help with this issue.... like i wish to
    record the number on users on all my 525 pages on my site and add them all together into 1 number
    that i show on the front page of my site (not just the ppl viewing that 1 page).... if anybody could
    help i'd be very thankful thank you!....
  12. How Can You Spice Up Your Basic HTML Site ? Beginner Needs Help
    (9)
    Well im new to this,and i know a person who knows how to do HTML,I of course dont lol,but I was
    wondering with html can you change the way the sites you make on here look and ect..(put flash in
    and w/e..)....
  13. Embeding Font Files
    How To Embed Fonts To Your Site (1)
    A lot of web designers run into the same problem of wanting a certain font type, but the question
    comes up "How do I guarentee the font to show up without the viewer's computer to install the
    font on the computer?" it's easy, just follow these steps. The first thing you have to do is
    download and install Weft 3 from microsoft, it's free, the download link is on that page. the
    easiest way you can embed a font is by using the wizard and follow the steps commanded to you.
    Easy, but what if you really want to know how the program works, or don't want to....
  14. Good Site To Download Web Templates ?
    (21)
    could anyone recommend a place to download (preferably free (as im not sure i can make it work))
    some (or a) good web template(s), something easy to use and not too complicated! thanks chris
    p.s just needs a couple pages of text (preferably with some graphics which i can change), some
    contact info and links to galleries which i have already made.....
  15. Free Shoutbox For Your Web-site
    And a cool one at that ;) (12)
    Hi guys, Those who want to avoid the extensive process of setting up a shoutbox on your own
    web-site (messing around with a whole bunch of PHP Code and MySQL Databases in the process) - can
    grab one for FREE rightaway from YellBox. I found out about their site a couple of hours back -
    and it's looks real good. Check out: http://yellbox.com Here's a list of their features:
    QUOTE     *  Instant feedback from visitors you would not hear otherwise.     * Allow your
    visitors to communicate or help each other.     * Greater sense of community will keep visit....
  16. Programing My Site
    (4)
    Hey, I just got hosting and I need help to program my site. How do I get a forum program on the
    front of my site. I cant change the design or anything. Can some1 please help me. THAnks
    jrdonjar0591 Edit -> Moved topic to more suitable location (Webdesign and HTML in the design
    category) -- Moon....
  17. Find Out Dead Links In Your Site Automatically
    Want to see a dead link on your site? (11)
    If you try to go to http://www.dead-links.com you will be asked for your domain or url. Enter it
    and the bot will find any dead links that you might not have seen. Have a nice day.......
  18. How Do You Put Flash Into Your Site?
    Help plz... (7)
    Hi, im makin a games site for Tasty Relish Forum. (go here to join and help fill this
    forum!!!) how do I embedd flash games?....
  19. Get Afree Template For Your Site
    (3)
    there is some site whic give u free html templates wich can be so easy to u to design ur own site
    lets share it to find the best i will add the sites i use effex media
    http://www.templatesweb.com/ ....
  20. What Is The Best Language For Web Site ?
    What is the best language for web site ? (23)
    Which is the best language, for a web site ? Topic moved, this suits better here, in the
    design/websites forum /wink.gif' border='0' style='vertical-align:middle' alt='wink.gif' /> --
    MoonWitch Moved again. Out of Howto's and Tutorials into Designing > Web Design. ....
  21. Help! Redirecting After Loading .mov
    (2)
    You know I believe there is some serious lag going on. I just got my post erased for the THIRD time.
    Gah. Anyway, I seriously tried to search (and destroy) this problem and mine but I just can't
    find the specific solution. Well, I thought I had a good lead on some other site, but then turns out
    you had to PAY TO SEE THE ANSWER. Those bastards. Hip hip for astahost! This place is turning
    out more useful than I thought... /biggrin.gif' border='0' style='vertical-align:middle'
    alt='biggrin.gif' /> So here's what I have and here's what I want to do: .....
  22. Wap Sites
    Do you have a WAP site? (4)
    Do any of you guys have a WAP site or has an interest in making one? How many of you have used a
    wap browser or even used your cell phone to access a wap site? I know some people don’t care about
    cell phones other that to make call, but the technology is here to stay. Like computers the cell
    phone will be integrated with every aspect of communication and is constantly expanding. The WAP
    protocol is the leading standard for information services on wireless terminals like digital mobile
    phones and Personal Digital Assistants (PDAs). WML is the language used to create p....
  23. Web Site Trackers?
    (8)
    Hi guys! I need for my site a kind of a tracker, that will show me how many peoples enetred my
    sites, what pages they view, where are they come from? I need detailed information on my
    visitors! is there any such a service for free? plz help!thanks!....
  24. Why A Site Is Viewed Differently In Browsers
    (12)
    hi guys! I have a real big problem... I have made my site, and in explorer it is viewd
    perfectly! When I loaded it on Mozilla Firefox, the first page looks like in explorer, but
    others are so ugly! a cell from the table is moving much more to the right!!! what
    can I do? Why is so? does it help visitors, if I write: best view: internet explorer ? thanks!....
  25. Website Review
    Please Review this simplistic site (11)
    I just posted a simple designer site, you comments would be appreciated.
    http://www.pbolduc.astahost.com Please feel free to critique any of the completed sites as well.
    Also would like your opinion on the header of this site under construction (load time)
    http://www.pbolduc.astahost.com/protectSoftware/index.php The links are broken coming off the
    page. Thanks, pete....
  26. Add A Search Box To My Web Site
    how to? (10)
    I don't know If this topic I should post here, but I'll try! I have a web site and i
    really need to add to my website a feature like searching on the site!I need a simple text boxt
    and a button, that will search the site content! are there already done version of such
    programs? pleasee help! thanks you!....
  27. Free Templates
    Great site! (3)
    I found a website with all free web and flash templates! They're really cool! I have 3
    of them ready to install now! Just go to www.notemplates.com and sign-up free and download as
    many as you want! They offer only free templates in many genres! I like them a lot because
    the templates look really professional and they're free!....
  28. Site Designing
    (21)
    Do any of you guys have a particular process you go through when designing a site? I always find it
    really hard to get started on a site, and often have to have 4 or 5 gos before I get it right. Is
    there a "perfect formula" out there for getting your designs right every time?....
  29. Help me
    I want to make site to the linux beginer (3)
    Please help me, give me ideas. I want to create a place to help to all the persons that want to
    learn linux. I have ideas but I now you have better ideas. My main idea is to show that everything
    that is done in windows can be done in linux. As see movies, play music and create sites webs.....
  30. Music On My Site?
    (18)
    Does enyone know how to add background music to your webpage? Can you do it using html???
    /mellow.gif' border='0' style='vertical-align:middle' alt='mellow.gif' /> Moved to Designing >
    Web & HTML . Absolutely wrong forum. ....

    1. Looking for redirecting, htm, files, php, site

Searching Video's for redirecting, htm, files, php, site
Similar
Website
Navigation
Hover
Buttons
Stick So
Made Css
Today - need
further help
with
tutorial
from this
site
Stretching
My Site
Vertically -
Using CSS or
HTML
Unicode
Encoded Site
- Characters
Not
Displaying
Properly?
Cvs For
Maintaining
Your Site
Need Help
With
Multi-lingua
l Site
Design
Thinking
About An
"audio&
quot; Web
Site - Your
feedback
please
Help Choose
A New Banner
For Me
Please -
Help needed
to choose a
new banner
for my site
How Do I
Keep A
Background
On My Site
With Or
Without
Tabs? - help
me choose
design for
my site.
Embedding
PSD Files
Into
Dreamweaver
- Embedding
PSD files
into
Dreamweaver
How To
Display XX
Users Online
On Your Site
?
How Can You
Spice Up
Your Basic
HTML Site ?
Beginner
Needs Help
Embeding
Font Files -
How To Embed
Fonts To
Your Site
Good Site To
Download Web
Templates ?
Free
Shoutbox For
Your
Web-site -
And a cool
one at that
;)
Programing
My Site
Find Out
Dead Links
In Your Site
Automaticall
y - Want to
see a dead
link on your
site?
How Do You
Put Flash
Into Your
Site? - Help
plz...
Get Afree
Template For
Your Site
What Is The
Best
Language For
Web Site ? -
What is the
best
language for
web site ?
Help!
Redirecting
After
Loading .mov
Wap Sites -
Do you have
a WAP site?
Web Site
Trackers?
Why A Site
Is Viewed
Differently
In Browsers
Website
Review -
Please
Review this
simplistic
site
Add A Search
Box To My
Web Site -
how to?
Free
Templates -
Great
site!
Site
Designing
Help me - I
want to make
site to the
linux
beginer
Music On My
Site?
advertisement




Redirecting All Htm Files To Php Site...



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE