Forum Moderators: phranque

Message Too Old, No Replies

.php to .html rewrite

help needed

         

thriller aus

7:08 pm on May 22, 2006 (gmt 0)

10+ Year Member



hi

i have a website, and my client need to convert the .php extension into html. Give me the exact url_rewrite or masking mode which i can use and incorporate with .hta file.

Please help me!and if we convert the file into .html suppose if i have a query string how i will write my code.

Please help me

WocitJC

9:58 pm on May 22, 2006 (gmt 0)

10+ Year Member



I'm no expert - only passing along what I got to work on my site.

Basically, the search engines had indexed .htm files and I wanted to auto-redirect to my new php files.

You can see from the comments that the code was originally used to go from htm to phtml - I just changed the extension to php and it works correctly.

NOTE: If you're using this for your whole site (multi-directory), then you'll need to put this in an .htaccess file in each directory. That's what I had to do to get it to work. Unless, of course, one of the masters of Apache here can help you with that...


RewriteEngine on
RewriteBase /
# parse out basename, but remember the fact
RewriteRule ^(.*)\.htm$ $1 [C,E=WasHTM:yes]
# rewrite to document.phtml if exists
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [S=1]

thriller aus

2:35 am on May 23, 2006 (gmt 0)

10+ Year Member



is it convert the php into htm files?

WocitJC

12:28 pm on May 23, 2006 (gmt 0)

10+ Year Member



what the excerpt of code I provided does is this: if you had a document (foo.htm) on your server and recently renamed it to foo.php, the link that goes to foo.htm would now be redirected to foo.php - you wouldn't have to try and correct any incoming links...they'd be automatically fixed.

If that is not what you want (it sounds like it, from your question), please explain more in detail as to your problem and how you'd like to see it fixed.

jdMorgan

2:13 pm on May 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A note and a warning: The code above is an internal rewrite, not an external redirect.

It is also missing at least one rule at the end, since [S=1] means to skip the next rule. If that rule is not present, and the requested .htm file does not exist as a .php file, then unpredicatable results will occur.

What's missing is something like:


RewriteCond %{ENV:WasHTM} ^yes$
RewriteRule ^(.*)$ $1.htm [L]

The last rule needs to put the previously-removed .htm back on the filename, so that the action is:

"If requested filename.htm ezists as filename.php, then serve filename.php, else attempt to serve requested filename.htm, and use default 404 error handler if it is missing."

I believe this code was taken from the Apache URL Rewriting Guide [httpd.apache.org], so refer to that document for an authoritative code sample.

Jim

thriller aus

5:17 pm on May 23, 2006 (gmt 0)

10+ Year Member



hi

no its not working. My question is so simple. I have a dynamic pages in my website, so i want to show as a .html or .htm to all the user instead of .php extension.

Jim will you please write the code so that i can refer that one.

Regards

jdMorgan

9:02 pm on May 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



We do not write code on demand here, because there would simply be too many requests for the limited number of contributors to sustain. Please review our forum charter [webmasterworld.com].

But we will try to help you learn how. Start here [webmasterworld.com].

Jim

thriller aus

2:05 am on May 24, 2006 (gmt 0)

10+ Year Member



then if i have any doubt, i will disturb you.(:if you dont mind. Because i am zero in apache except php,.net and asp.

catch you soon