5 replies
Is there a way via .htaccess file that I can forward all html requests to php?

I purchased an expired domain and have recreated many of the files using the same file names (by looking at at archived content and directory listings in google and yahoo) however, I am using php -- the old site was apparently built using html. I am getting lots of 404 errors to html files.

Thanks in advance.

Linda
#htaccess #question
  • Profile picture of the author dvduval
    There are a couple of strategies you can use here. First you can actually have php code in a .html document. In that can you can use this in your htaccess file
    RemoveHandler .html .htm
    AddType application/x-httpd-php .php .htm .html
    Otherwise, you just need to setup a redirect from the php file to the html file. Here is a pretty good link for that
    301 Redirect - How to create Redirects
    Signature
    It is okay to contact me! I have been developing software since 1999, creating many popular products like phpLD.
    {{ DiscussionBoard.errors[891031].message }}
    • Profile picture of the author Linda Van Fleet
      Thanks. I've tried a few things already:

      Options +FollowSymlinks
      RewriteEngine on
      RewriteRule ^(.+).html$ http://mysite.com/$1.php [R,NC]
      and I still get a page not found.

      Then, I tried this:

      Options +FollowSymlinks
      RewriteEngine on
      RewriteRule ^(.*).html$ $1.php [NC]
      That didn't work, either.

      I created the site with wordpress, and changed the permalink structure to %postname%.php so in reality either of the above should work. I'm thinking it most be conflicting with the standard wp htaccess in some way.

      I have been studying the info found here: .htaccess tricks and tips.. part two: url rewriting with mod rewrite. .

      I have a dedicated server so I know I have mod_rewrite ... works on all 20+ of my other sites. The .htaccess looks okay -- I am befuddled with this. :-\

      Linda
      {{ DiscussionBoard.errors[891119].message }}
  • Profile picture of the author mrmcd
    RewriteEngine on
    RewriteBase /
    RewriteRule ^(.*)\.html$ $1.php [L]
    {{ DiscussionBoard.errors[891149].message }}
    • Profile picture of the author Linda Van Fleet
      I wanted to update this thread to clarify a couple of things.

      First of all, adding a directive to the htaccess file didn't work. I tried everything I know and stuff I didn't know as well (what a learning experience!).

      The problem is that Wordpress doesn't really have pages sitting there waiting for someone to visit them. Even though I changed the permalink structure to %postname%.php - it wasn't really a .php file - it was still a dynamic page. That's why the rewrite rule wouldn't work.

      I could have put a redirect command (ex: redirect thisfile.html thisfile) in the htaccess file for each page - but that would be too much on my system. An htaccess file shouldn't be used to redirect hundreds of pages with a directive for each page.

      So ... my final solution: I am creating a meta refresh redirect for each html file and, when someone calls for the html file by that name they will be redirected immediately to the wordpress post by the same name. A little work - but it works. (A meta refresh redirect is placed in the head of the html page like this: <META http-equiv="refresh" content="0;URL=http://mysite.com/name-of-wordpress-post">

      I'm sure there's a better way out ther and if anyone knows what it is - please share! It would be nice to know for future.

      Linda
      {{ DiscussionBoard.errors[894413].message }}

Trending Topics