king arthur Posted July 5, 2007 Share Posted July 5, 2007 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? Quote Link to comment Share on other sites More sharing options...
hackerkts Posted July 6, 2007 Share Posted July 6, 2007 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. Quote Link to comment Share on other sites More sharing options...
king arthur Posted July 6, 2007 Author Share Posted July 6, 2007 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. Quote Link to comment Share on other sites More sharing options...
hackerkts Posted July 6, 2007 Share Posted July 6, 2007 You can try this Options +Indexes Options +FollowSymlinks RewriteEngine on RewriteRule ^(.*)$ page.php?url=$1 Quote Link to comment Share on other sites More sharing options...
king arthur Posted July 6, 2007 Author Share Posted July 6, 2007 Well that should work on a simple level. But it doesn't - all I get is the url page.php?url=page.php I can't see how it is doing this. Any ideas anyone? Quote Link to comment Share on other sites More sharing options...
king arthur Posted July 6, 2007 Author Share Posted July 6, 2007 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. Quote Link to comment Share on other sites More sharing options...
hackerkts Posted July 7, 2007 Share Posted July 7, 2007 Ops sorry, the previous 1 I forgotten to put .html, so it could only be access by http://domain.tld/some-page Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.