/    Sign up×
Community /Pin to ProfileBookmark

Controller for restful access?

For a small-ish site not requiring any particular security, I’m thinking of implementing direct access to certain items, converting [I should say “adding” here – I don’t want the current mechanism to go away] from a url like this:
www.example.com/sports.php?sport=ping-pong
to
www.example.com/ping-pong

Currently, if you type that second url on my site, it redirects to a custom 404 page, where I could easily parse ‘ping-pong’ and do what I want. I there a more appropriate way, though, to make this central hub and direct urls that aren’t otherwise caught by actual file links to it?

All my code is php, no other shiny add-ons.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogSep 23.2021 — I think typically this would be initially driven by .htaccess patterns that determine whether a given request gets routed to a "controller" script (which then looks at the URL and decides what to do with it), or if not then just gets passed on as a "normal" HTTP request.

For example, on an admittedly old app I work on, we have this, which basically routes everything that isn't to the /static directory to our PHP controller:
<i>
</i>DirectoryIndex controller.php
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine on
RewriteRule ^favicon static/favicon.ico
RewriteRule !^static controller.php
&lt;/IfModule&gt;
Copy linkTweet thisAlerts:
@tracknutauthorSep 23.2021 — @NogDog#1637505 Thanks, I will fiddle with this setup and see if I can get it going.
×

Success!

Help @tracknut spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...