You are here: Re: can you redirect every existing html page through a php function? « PHP Programming Language « IT news, forums, messages
Re: can you redirect every existing html page through a php function?

Posted by d on 11/18/23 11:43

"Stephen Kay" <sk@karma-lab.nospam.com> wrote in message
news:C04D0075.5A945%sk@karma-lab.nospam.com...
> Is there a way to redirect every single page on an existing web site
> through
> a php function?
>
> In other words, say I have a whole functional HTML web site, never written
> to use any php. Now I would like to have a php function handle displaying
> every page, for example, instead of:
>
> http://www.mysite.com/mypage.html
>
> you would call:
>
> http://www.mysite.com/dopage.php?p=mypage.html
>
> ...and then the php could do some fancier includes at the end of each
> page,
> etc., or add a header, etc.
>
> I don't want to rewrite the whole site and rename all the pages; also,
> this
> site has been around for awhile and there are a lot of links floating
> around
> the internet to direct urls on the site, so I'm wondering if I can
> intercept
> every URL to that site and redirect it to the php function, which will
> then
> open the page.
>
> Thanks for any advice on this...
> --
> Stephen Kay
> Karma-Lab sk@karma-lab.NOSPAM.com
> ^^^^^^^

If you're running Apache, you could use a rewrite rule to redirect all
requests for .html files which exist like this:

RewriteEngine On
RewriteCond /var/www/docroot%{REQUEST_URI} -f
RewriteRule .* /var/www/docroot/fancy.php [L,NS]

(untested, btw)

and in fancy.php look at the $_SERVER["REQUEST_URI"] variable to get the
name of the HTML which was requested. The RewriteCond will ensure the PHP
is only called when the page exists. If you want to have 404 messages, you
can remove that line, and maybe check for just .html. Personally, I have
all requests for non-existing files going through a PHP file, to handle
site-wide database connections, templates, etc.

hope that helps!

dave

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация