php on index.html

by 8 replies
10
I'm trying to put a php on my index.html page.
when I view the page I see the actual code.

Unsure what's going on I read a few things to see why. If I understood correctly I have two options.

one is to put something in the htaccess file to allow the php on the HTML page
or other option is to rename index.HTML to index.php and then just redirect index.HTML to index.php.
is this correct?
#programming #indexhtml #php
  • All you have to do is give your index page a .php extension (rename it from index.html to index.php). Once you do that, there is nothing that you have to "redirect" (browsers know to look for index.html OR index.php, so you should only have a single index file).

    Alternately, if you already have a bunch of webpages that link to index.html and you don't feel like manually updating all of the links, then you can use htaccess to redirect index.html to index.php...

    Redirect 301 /index.html /index.php
    • [ 1 ] Thanks
  • Thank you. Wanted to make sure that was correct before doing so.
  • You could add one the following lines to your htaccess file:

    Code:
    AddType application/x-httpd-php .html .htm
    AddType application/x-httpd-php5 .html .htm
    Probably the second one will do the trick.
    • [ 1 ] Thanks
  • Changing the page name worked.

    Is it possibly to give me a basic example of a htaccess file? One to redirect the index.html to index.php and also one with robins example.

    I dont have one(htaccess file) so made one using what I found. I must have missed something as I ended up with just a white page.
  • A single line, using one of my examples should work if you are using one of the popular unix hosts. If not, the best solution would be to use your hosting support.
  • Thanks again. Everything I need to do is is working great.
    I ended up changing the page name to php and just used this in the htaccess:

    index.html http://subdomain.mydomain.com/index.php

    it only worked though if I used the full url for whatever reason.

    So if I type in my browser http://subdomain.mydomain.com/index.html, I get taken to the renamed php page(great).
    But if I add www before the url like this: http://www.subdomain.mydomain.com/index.html

    , i get some DNS page rather than being redirected.

    Did I miss something or have to add something else or just contact my host?
    • [1] reply
    • Add this at the beginning of your htaccess file

      Code:
      RewriteEngine on
      RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]
      RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
      • [1] reply

Next Topics on Trending Feed