Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8157527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:18:57+00:00 2026-06-06T17:18:57+00:00

I’ve looked for a while on this subject and there doesn’t seem to be

  • 0

I’ve looked for a while on this subject and there doesn’t seem to be much in the way of this specific question. I did find one answer out of hundreds that I think answers my question, but I’d like to make sure of the point. My question is, what is the best and most common way to handle a REST URI server side?

To elaborate, if I have have a URI, http://www.example.com/resources/resourceID, I know that I need to set up a .htaccess file to handle that and direct it to the right place. I am simply unsure whether it is cleaner to have a PHP dispatcher which simply parses the URI and sends off the request to specific classes (i.e. some giant switch statement that handles all HTTP methods and all possible combinations of requests that a consumer can use) or to have the .htaccess parse them. That is, do I use the .htaccess file to route the example URI to say restHandler.php or just parse it with a regex to go to a class called ‘Resources’.

This may answer my own question, but my problem with the .htaccess method is that something like http://www.example.com/resources1/resource1ID/resources2/resource2ID would be hard to capture in a regex which sends it to an appropriate file, so I lean toward a handler in PHP. But it still doesn’t seem clean to me to have a big ‘ol switch/ifelse statement to handle each possible combination that I allow. Is this really the cleanest way to go?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T17:18:58+00:00Added an answer on June 6, 2026 at 5:18 pm

    The best solution is a mixture of the two: use .htaccess to capture the whole /resources1/resource1ID/resources2/resource2ID part and redirect to a fixed entry point where this will be passed as a parameter — for example, to

    example.com/dispatch.php?route=/resources1/resource1ID/resources2/resource2ID
    

    Your PHP code can then decide what to do with this information utilizing information that can be as rich as you want it to, including information it can gather itself at runtime (e.g. through reflection). Typically this dispatcher would utilize some kind of routing¹ to determine which controller and action should be invoked and then some type of parameter binding² to call that action with the appropriate parameters.

    It could also be done through a giant switch statement, but that’s probably not the best idea. 😉


    ¹ routing: mapping URL patterns to controller actions; here’s relevant reading applicable to ASP.NET, but the concept is common to all MVC frameworks

    ² binding: figuring out how parameters present in the URL map to formal parameters of the method that implements a controller action

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.