Friendly URL's and SQL

Discuss practical ways rearrange URLs using mod_rewrite.

Friendly URL's and SQL

Postby pleasehelpme » Sun Feb 15, 2009 4:02 pm

Hi,

I want to change http://www.mywebsite.co.uk/properties_v ... editid1=10 to something like
http://mywebsite.co.uk/country/city/propertyname.htm where country, city and propertyname are columns in the properties tablename.

I'm not quite sure how to do this as am quite new to SQL (I posted before and had no idea what I was talking about, but now I know a little bit...)!

I have 2 additional problems, some of my fields have spaces and other carachters which are not suitable for URL's so these need 'cleaning' too.

Aditionally when I have done manual rewrites I have realised that the pages are not formatted correctly because they require information in the folder http://www.mywebsite.co.uk/includes - Is there a way to use mod_rewrite to get around this problem by using another rule?

Hope this makes sense?

Thanks in advance
pleasehelpme
 
Posts: 2
Joined: Wed Sep 24, 2008 4:27 pm

Postby richardk » Tue Feb 17, 2009 2:14 am

FAQ: How to change a numeric ID into a name/title.

I want to change /properties_view.php?editid1=10 to something like
/country/city/propertyname.htm where country, city and propertyname are columns in the properties tablename.

I'm not quite sure how to do this as am quite new to SQL (I posted before and had no idea what I was talking about, but now I know a little bit...)!

You currently have a query like
Code: Select all
SELECT columns FROM table WHERE id=1

and you would change the id=1 part to use the property name instead (and possibly the country and city depending on your database structure).
Code: Select all
SELECT columns FROM table WHERE property_name="Your House"


some of my fields have spaces and other carachters which are not suitable for URL's so these need 'cleaning' too.

Most scripts create a URL slug, which is a cleaned up unique version of the name/title and save it in the database. Then that is used instead of the ID or name/title
Code: Select all
SELECT columns FROM table WHERE property_slug="your_house"


Aditionally when I have done manual rewrites I have realised that the pages are not formatted correctly because they require information in the folder http://www.mywebsite.co.uk/includes - Is there a way to use mod_rewrite to get around this problem by using another rule?

FAQ: Relative paths to images, JavaScript, CSS and other external/linked files are broken.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 24 guests

cron