-3

I have a website with rental properties and want to change the url with mod_rewrite .htaccess and mysql.

http://www.example/property.php?id=2112

into

http:/www.example/house/spain/costa-del-sol/malaga/2112

each property is in a table called HOUSE I need to get the url stored in the table by referencing the id number.

HOUSE
id - 2112
......
......
......
url - http://www.example/house/spain/costa-del-sol/malaga/2112


I am a newbie to this mod rewrite stuff, I figured I need somesort of .htaccess file that redirects to a php file to do the lookup. Is there a way in .htaccess to only do this lookup if the filename is property.php?id= - otherwise go to my 404.php

Regards

Martyn

zerkms
  • 249,484
  • 69
  • 436
  • 539
Martyn
  • 3
  • 1
  • Same question as : [http://stackoverflow.com/questions/21766177/hide-index-php-from-url-and-get-parameters][1] [1]: http://stackoverflow.com/questions/21766177/hide-index-php-from-url-and-get-parameters – JooO Feb 13 '14 at 21:59
  • And due to the second reason, it is unlikely any answer will be helpful, or that this question will be helpful to other people. – Sumurai8 Feb 14 '14 at 09:44
  • Thanks JooO for the pointer to that previous question, it gives me great info to help try and understand this. At times research is difficult if you cannot always explain what you are trying to accomplish. – Martyn Feb 14 '14 at 10:52
  • 1
    @kingkero - Perhaps you should read this: http://meta.stackexchange.com/a/215546/135615 – Brad Larson Feb 17 '14 at 19:12

1 Answers1

2

You can add a URL Rewrite rule:

RewriteRule    ^house/spain/([0-9]+)/?$    property.php?id=$1    [NC,L]

To get:

http://www.example/house/spain/2112

If you want add some informations, such as costa-del-sol and malaga, you need this:

RewriteRule    ^house/spain/([A-Za-z]+)/([A-Za-z]+)/([0-9]+)/?$    property.php?location=$1&city=$2&id=$3    [NC,L]

location and city fields are for example.

[NC,L] - "Flags", that tell Apache how to apply the rule. In this case, we're using two flags. "NC", tells Apache that this rule should be case-insensitive, and "L" tells Apache not to process any more rules if this one is used.

  • 1
    Many thanks again to all - this has now given me a good pointer on constructing the very confussing Rewrite rule. Again thanks to all – Martyn Feb 14 '14 at 10:54