Jump to content

Rewrite static html pages to dynamic php


king arthur

Recommended Posts

I know nothing of mod rewrite, never had to use it before.

 

I have a project which is a directory consisting of many html pages, one for each entry in the directory. Each page is named after the person the directory entry is for, e.g. some-one.html, someone-else.html etc. Things are complicated slightly by the fact that some pages are in another directory so the relative url is e.g. 2/an-other.html

 

There are also pages such as index.html, search.html, etc.

 

I have written the php to output each page dynamically and it takes the form page.php?url=some-one.html or page.php?url=2/an-other.html and outputs the page accordingly regardless of which directory the original html page was in.

 

The site owner wants to ensure all the urls stay the same so he doesn't lose bookmarks or serps.

 

So I need a set of mod rewrite rules that give me:

 

index.html => index.html

search.html => search.html

etc.

 

some-one.html => page.php?url=some-one.html

2/an-other.html => page.php?url=2/an-other.html

etc.

 

Can anyone help?

Link to comment
Share on other sites

Hmm.. First of all I find it no point make it into a dynamic page, anyway..

I don't think you will need mod_rewrite it, in your page.php you just need a short code

<?php
$url = $_GET['url'];
if (isset($url)) {
include($url);
}
?>

 

Note: This is just an example if page.php, you will need to modify to make it safer.

Link to comment
Share on other sites

Not the answer I was looking for. Of course there is a point making it into a dynamic page! If you read my post you will see that the site owner needs the urls to remain the same whilst having the pages generated dynamically, because some of the pages will be bookmarked already by surfers and will already be indexed by the search engines. I don't need a lesson on how to dynamically generate html pages, I need advice on how to write the mod rewrite rules as that's where my knowledge is lacking.

Link to comment
Share on other sites

Well for some reason it didn't like the $

 

So I have rewritten it as RewriteRule  ^(.*)\.html page.php?url=$1.html

 

which seems to work. I'd still like to know why the previous one didn't work. And what the best way would be to exclude certain html page urls from being rewritten.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.