Forum Moderators: coopster

Message Too Old, No Replies

Redirect HTML -> PHP

Redirecting HTML pages to PHP pages

         

tchallies

8:22 pm on Sep 28, 2004 (gmt 0)

10+ Year Member



I have a site that is about to transition from all HTML pages to all PHP pages. The page names will remain identical with only the extensions changing. Is there a simple solution so that anyone coming in via bookmarks or search engines and accessing a .html page will be seamlessly forwarded to the identical .php page?

Josefu

8:49 pm on Sep 28, 2004 (gmt 0)

10+ Year Member



Yes, there is, if your site is on an Apache server. You'll have to use a function called 'mod rewrite' of which you will find tons of things written here at webmasterworld. If you're not Apache... actually I don't know so perhaps someone else can help you. Do a search for the terms you used in your question and I'm sure you'll find something.

Good luck!

PS: welcome to Webmasterworld!

bedlam

9:16 pm on Sep 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Heya,

If all of the pages are going to be php pages and you're using Apache, why not just leave the .html extension in place and set up Apache to parse .html pages as .php [google.com]?

-B

Hanu

9:23 pm on Sep 28, 2004 (gmt 0)

10+ Year Member



If you use Apache:

1) Do not name your PHP files ".php". Keep the names and add this line to your .htaccess file.

AddType application/x-httpd-php .html

This causes all html files to be fed to PHP.

If this doesn't work for you, a mod_alias or mod_rewrite might be offer a solution.

2) mod_alias:

RedirectMatch 301 ^/(.*)\.html$ [yourdomain.com...]

This redirects the user's browser (and GoogleBot) to the php-page when they request the html page. To avoid unnecessary redirection change all internal links to point to the php-files. Redirection is overhead so the AddType solution might be better.

3) mod_rewrite:

RewriteEngine On
RewriteBase /
RewriteRule ^/(.*)\.html$ /$1.php

Make sure you read the acording Apache docs so you understand what the above directives do. I didn't test them. They should only give you an idea.

5x54u

9:57 pm on Sep 28, 2004 (gmt 0)

10+ Year Member



Forgive me for jumping in;

Does anyone have a solution to tchallies problem IF it were on a Windows box?

TY

mincklerstraat

7:34 am on Sep 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



mod_rewrite also works on windows, I believe. If it were a windows asp box, google for 'asp mod_rewrite', there's sort of an equivalent of mod_rewrite that's been written for asp, but I've forgotten its name.

ergophobe

1:44 am on Sep 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Minck,

I think you misspoke. In any case...

ASP is a scripting language and has nothing to do with URL rewriting.

mod_rewrite works with the Apache server. If you're running Apache under Windows, mod_rewrite works exactly as it does under *nix as near as I can tell, regardless of whether you're using ASP or something else. If you're using IIS, you need something else. Search on

IIS url rewriting (no quotes)

and you'll get lots of stuff.

mazoboom

2:09 pm on Oct 29, 2004 (gmt 0)

10+ Year Member



Hey, guys I found this through google. I tried it and it worked completely well, except one problem. Now my subdomain redirects to my main page. (Sucha s forum.domain.com redirects to www.domain.com). I understand why it's happening, I just don't know how to mess with htaccess enough to know how to fix it. any help would be great.

thanks.

mazoboom

2:14 pm on Oct 29, 2004 (gmt 0)

10+ Year Member



Oh, yeah sorry. I used the "mod_alias" one.