Reputation: 3935
I have created a real estate website and on it I want to add some rewrite rule to make urls seo friendly. Mainly I want to do this on property details page. Right now the property details page URL is like this
http://www.my-website.com/property_details.php?id=11&slug=westbourne-grove-serviced-offices
So I am passing the property ID and a Slug text of the property name. This slug is not being used anywhere at the moment, so the property details are going to be fetched only by using the ID.
Now I want to change the URLs to
http://www.my-website.com/property/westbourne-grove-serviced-offices-11
So the slug text comes first and the property id is merged in the end using dash "-". I have no knowledge on creating rewrite rules. Any help will be appreciated.
Thank You
Upvotes: 1
Views: 826
Reputation: 785146
You can use this code in your DOCUMENT_ROOT/.htaccess
file:
RewriteEngine On
RewriteBase /
RewriteRule ^property/(.+?)-([0-9]+)/?$ property_details.php?id=$2&slug=$1 [NC,L,QSA]
Upvotes: 3