0

I'm working on a directory with Cities & States - the site has been operational for several years - but I have always wanted to make the urls clean.

I have been seeing this done (especially through wordpress)

Here is what url looks like currently:

website.com/directory/index.php?state=5
California Directory

website.com/directory/index.php?state=5&city=2292
Long Beach California Directory

Here is how I would like the url to look:
website.com/directory/california/
website.com/directory/california/long-beach

My main database consists of 51 states ID numbers, including District of Columbia (with state abbreviation & full state name) and 1,847 Distinct Counties with 29,640 Distinct city ID numbers with 41,580 zip codes it also has the latitude & longitude for each, in order to generate maps.

There is another database with several categories/services listed for each city ID. (Example: janitorial, gardening/landscape, pest control, real estate, etc.) Then there are various business listed under each category.

These are displayed currently:
website.com/directory/index.php?state=5&city=2292&svc=1
website.com/business/index.php?bid=10

Here is how I would prefer the urls to appear:
website.com/directory/california/long-beach/gardening/
website.com/directory/california/long-beach/gardening/joes-lawn-service/

or
website.com/business/joes-lawn-service/

I greatly appreciate any assistance with figuring this out. I looked at many options but I haven't found any that discuss and demonstrate using a database to gather the information.

CWT
  • 1
  • 3
  • 2
    Questions asking for code must **demonstrate a minimal understanding of the problem being solved**. Include attempted solutions, why they didn't work, and the *expected* results. See also: [Stack Overflow question checklist](http://meta.stackexchange.com/questions/156810/stack-overflow-question-checklist) – Danny Beckett Jul 12 '13 at 02:29
  • @Danny - I appreciate the response - however, I am not certain what you are requesting? I searched for code and I discovered the htaccess: `RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L]` But this did not address how to write the code on the index.php file to transform the information. – CWT Jul 12 '13 at 02:50
  • What he probably wants to say is: "What have you tried so far?" – Patrick Manser Jul 12 '13 at 04:54
  • BTW: http://forum.codecall.net/topic/74170-clean-urls-with-php/ Does this help? Haven't tried myself, but looks promising – Patrick Manser Jul 12 '13 at 04:57
  • @PatrickManser - Yes, that is what I reviewed but it didn't address using a database to retrieve the information. I also took a look at [link] (http://www.cutcodedown.com/tutorials/friendlyURL/) the author states that the information can be drawn from a database but doesn't provide details. - I'm trying to figure out what coding to use to accomplish this. I know how to code with php to access the database using queries but I would like to hide those queries from the address bar. – CWT Jul 12 '13 at 18:07

1 Answers1

0

I think this is what you are looking for: .htaccess routing php (similar question)

It's basically catching the all requests using that path and letting the configured php file take care of the processing (which you will have to implement).

The pattern the question asks for is generally used to implement web API's and which is why I was also curious to what the actual solution is. Contrary to what is proposed in the solution in regards to the QSA flag, I would keep it.

This other link: What does $1 [QSA,L] mean in my .htaccess file? should point you in the right direction for understanding the directives in the .htaccess file.

NB: I would like to state that I don't think all questions asked require code as stated by some in the comments to the question as long as they are properly formulated. Sometimes we know of a concept, but no knowledge of how it should be implemented in a development environment to which we are new.

Community
  • 1
  • 1
LostBalloon
  • 1,608
  • 3
  • 15
  • 31