Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: htaccess php html

  1. #1
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default htaccess php html

    ive tried adding a htaccess file such as
    Code:
    AddType application/x-httpd-php .html
    so that i can keep my file extension html. however it does not work. and i read this in a similar post

    "SSI enabling is causing the problem. We also tested this using 2 external servers outside our network, one we disabled SSI and it worked and the second was a server with php loaded as an apache module with SSI enabled and it worked.
    So we concluded that since PHP is loaded as a cgi and SSI is enabled then parsing PHP within an HTML file will not work."

    does anyone know of a workaround?

    thank you

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    This doesn't exactly address your specific question, but I'm wondering why you would want to keep your .html extensions. If you're using php code on your pages, why not change the extensions to .php? And, since you're using .htaccess already, you can use rewrite rules to redirect any .html requests to .php files (to accommodate old bookmarks, for example):
    Code:
    RewriteRule ^(.*)?\.html$ $1.php [NC,L]
    Edit: corrected the regex. see my post below.
    Last edited by traq; 12-02-2009 at 07:05 PM.

  3. #3
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    i want to keep the extension html because the site is currently in that format and changing it would have an effect on search seo

  4. #4
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    i placed this inside htaccess but it does not redirect html extensions to php
    Code:
    RewriteRule ^[(.*)].html$ $1.php [NC,L]

  5. #5
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    I'm sorry, I made a few typos:
    Code:
    RewriteRule ^(.*)?\.html$ $1.php [NC,L]
    1. NO square brackets.
    2. ESCAPE (backslash) the dot.
    3. add a ? (ungreedy pattern match) after (.*)
    In addition, you must have mod-rewrite enabled. You may have to do this by placing the line RewriteEngine on at the top of your .htaccess file.
    This kind of redirect should not have any effect on your SEO. The url shown in the address bar will not change (e.g., it will still read "http://www.example.com/page.html", even though it's showing the user "page.php") because the redirect is done server-side. However, this means that ALL requests for .html pages will be served their .php equivalents, even if there isn't one... which could result in 404 errors. The easiest solution would be to rename ALL your pages with the .php extension.
    Last edited by traq; 12-02-2009 at 07:04 PM.

  6. #6
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    so this is my htaccess file
    Code:
    RewriteEngine on
    RewriteRule ^(.*)\.html$ $1.php [NC,L]
    here is a test link: http://www.2020proj.com/notes/htmlphp/films.php
    it still does not work

  7. #7
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    its linking but getting an error
    Last edited by ggalan; 12-02-2009 at 07:07 PM.

  8. #8
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    did you put the question mark? it works on my server: http://www.custom-anything.com/htacc.../redirect.html (<-- actually a .php file)

  9. #9
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    where do i put the '?' mark

  10. #10
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Code:
    RewriteEngine on
    RewriteRule ^(.*)?\.html$ $1.php [NC,L]

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •