Re: Using Apache's mod_rewrite to hide scripts extension



Jerry Stuckle <jstucklex@xxxxxxxxxxxxx> wrote:

Oops - I think I misread what you are doing (twice!).

If I understand this correctly now, you have your PHP code in .php
files, and have Apache set up to load those PHP files if the equivalent
.html is called. This would be OK.
...
But you don't want the .php files to be able to be loaded directly. I'm
not sure what difference it makes - does it cause a problem to load the
.php file?

From the PHP end, yes, you can restrict access. But if you want to do
it with mod_rewrite, you really need to be following up on an Apache
newsgroup. You'll get expert answers there.

mod_rewrite is one of those magical products that can be configured to do
practically anything (like Sendmail). And like most such products, it is
difficult to get right.

However, I think this will do what the original poster wanted:

RewriteEngine On
RewriteRule ^(.*)\.php$ $1.php [R=404,L]
RewriteRule ^(.*)\.html$ $1.php [L]

That says PHP references should redirect to a 404, and HTML references
should be rewritten to PHP.
--
Tim Roberts, timr@xxxxxxxxx
Providenza & Boekelheide, Inc.
.



Relevant Pages

  • Using Apaches mod_rewrite to hide scripts extension
    ... With Apache's mod_rewrite module I can keep *.php files and load them as *.html files: ... RewriteEngine On ... is there any elegant way to prevent direct access to ...
    (comp.lang.php)
  • Re: Navigation .gif not visible in .php file
    ... the .gifs in my Navigation bars are not ... showing up in my .php files. ... It sounds like FP2003 does like publishing the navigation .gifs associated ...
    (microsoft.public.frontpage.client)
  • Re: Redirecting between PHP Pages
    ... Display login form ... >>other php files, you should never need a redirect your page except to ... pass it on to smarty which then displays it as html for me. ...
    (comp.lang.php)
  • Re: Templates & PHP files
    ... Here's a link that explains how to make PHP function on an htm/ html page: ... > have added many PHP files to update my databases. ... > Problem is, whenever I make a change to a template, it only updates the ...
    (microsoft.public.frontpage.programming)
  • Re: New at setting up a database
    ... A PHP newsgroup is going to be your best resource, since you will need to learn the PHP scripting ... FrontPage Resources, WebCircle, MS KB Quick Links, etc. ... >>FP will not create PHP files, however you can use FP to ...
    (microsoft.public.frontpage.client)