Forum Moderators: phranque

Message Too Old, No Replies

rewrite problem on urls without common pattern

         

omoutop

7:08 am on Jun 2, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



In a new project, a website has a set of static htm pages. The owner needs to convert them to dynamic ones.
Each page has: a text section, a small photo plus some links towards other pages, related to this one.

All these i can put in database and create a dynamic page (php).

My problem is that each static page is unique - no common pattern in url. And there 860 such pages at the moment.
So, i can have one url like:
folder1/folder2/item1.htm or
folder1/folder2/folder3/item2.htm or even
folder1/folder2/folder2-fodler3/item3.htm.
These 3 are the most common patterns so far (serving around 650 urls out of the 860).


Each folder name is actually a category/subcategory/keyword i can use to determine the properties of my item
As a general rule, the first 2 folders (folder1 and folder2) are the category and subcategory of the product, while the next folders (folder 3 and after that) determines the section (if any) of the item.
I hope this makes sense.

Is is possible to construct a rewrite rule to serve these pages out of single php file?

g1smd

7:03 pm on Jun 2, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If the content is going in a database, then make the "URL path" one of the fields in one of the tables. Rewrite requests to the script which presents the path as a database query, then returns 404 if there is no record, or the content if there is.


RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) /script.php?path=$1 [L]

omoutop

6:07 am on Jun 3, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Good tip, but i have a problem.
From my limited knowledge, your rule is translated to something like: "If the request is for a file that exists already on the server, execute the rewrite rule (as last rule)".
Wouldn't this rule affect all dynamic driven content?

Or should i set this rule at the very bottom of my htaccess to be executed last, so as to make sure all other rules are unaffected?

g1smd

7:41 am on Jun 3, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



That should have read '
!-f
' for ' NOT a file '.

Well spotted!