Forum Moderators: phranque

Message Too Old, No Replies

Mod Rewrite (Once Again)

         

jp_css

1:40 pm on May 15, 2004 (gmt 0)

10+ Year Member



I want to know how to process an html file as if it were a php file (or how to process any extension as if it were php) with mod rewrite.

gergoe

2:13 pm on May 15, 2004 (gmt 0)

10+ Year Member



RewriteEngine on
RewriteRule (.+)\.original_extension$ $1.any_other_extension

for example to rewrite every file with the html extension to php, use

RewriteRule (.+)\.html$ $1.php

i suggest you to read about the mod_rewrite in the apache documentation anyway, this is a very easy rewriting, if you would have taken a look in it, you could have done the same rewriting by yourself

jp_css

3:09 pm on May 15, 2004 (gmt 0)

10+ Year Member



How about only rewriting one individual file from a html from a php file?

gergoe

6:20 pm on May 15, 2004 (gmt 0)

10+ Year Member



i have the impression that you are not going to read the mod_rewrite documentation in the near future. well, let it be then, here's what you are looking for:

RewriteEngine on
RewriteRule (.*)/somefile.html $1/somefile.php [L]

this will rewrite the address silently, which means that the url in the address bar will not change. if you want to have the browser redirected instead (so the url will change in the address bar) then change the
[L]
to
[R,L]
at the end of the last line.

jdMorgan

2:13 am on May 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In accordance with our charter [webmasterworld.com], members are asked to do their homework, and not ask others to write their code. The purpose of this forum is to discuss Apache Server, including mod_rewrite methods and code, but not to provide a "free code-writing shop." Those who want code written and tested, but do not wish to learn how to do it themselves can post in our Commercial Exchange Forum [webmasterworld.com] for bids on the job.

If someone posts their own code and asks for help with a specific problem, we'll help fix it.

"Give a man a fish, and feed him for a day. Teach a man to fish, and feed him for a lifetime."

Apache mod_rewrite documentation [httpd.apache.org]
Apache URL Rewriting Guide [httpd.apache.org]
Regular expressions tutorial [etext.lib.virginia.edu]

Jim