Forum Moderators: phranque

Message Too Old, No Replies

Static pages indexed, want them dynamic

.. but remain in the format .html

         

sniffer

5:04 pm on Jul 30, 2005 (gmt 0)

10+ Year Member



Hi

I have a slightly different question relating to changing file names. I have searched a fair bit but all of the questions i have found are of the kind "how to serve dynamic pages as static"

My situation is this:

I have a website full of static pages in the form .html that are indexed by the Search Engines -

Now, i need to have these pages serving dynamic content - without disrupting their listing in the search engines, and having to make redirects. Ideally, it would be best if the SE's didnt know any changes are made. Is this possible? So it will be as follows:

page1.html changes to page1.php, but then appear again as page1.html

OR

page1.html stays as it is, but can somehow serve dynamic content without having to change and 'hide' the filename (a better option)

any advice or experience with this issue would be greatly appreciated

Thanks

PS - i am a total apache n00b :)

jdMorgan

5:51 pm on Jul 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is just a matter of internally rewriting a requested static URL to a dynamic script call, with the page name and other parameters from the static URL moved to the query string. It takes one line of code, plus two lines of setup to enable mod_rewrite. Check out the documentation cited in our forum charter [webmasterworld.com] for background, analyze the following example character-by-character while referring to that documentation, and you'll be ready to take on this project.

While we are not set up to write code on demand here, here's an example to get you started. After some research, you can modify it to suit your needs, and we'll be happy to answer specific questions if you have trouble.

With an example static page url of example.com/product/widget.html and a script invokation of /display.php?what=product&product=widget, it's simply a matter of doing something like this:


Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([^/]+)/([^.]+)\.html$ /display.php?what=$1&product=$2 [L]

Put that code in your root-level .htaccess file, and that's it. As long as your server has mod_rewrite installed and the settings to allow you to use it, there's nothing more required, other than coding the "display.php" script to retrieve the query terms and create the correct page. ;)

Jim