/    Sign up×
Community /Pin to ProfileBookmark

probably a simple question

instead of displaying my urls like [url]www.mysite.com/?id=THE_ID[/url]
how can i make it mysite.com/THE_ID and get the same data?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMar 14.2011 — This is typically done via the web server, such as by using mod_rewrite in a .htaccess file on an Apache web server.
Copy linkTweet thisAlerts:
@DasherMar 14.2011 — The solution is to create links the way you want them to look, and then convert the link to an ID in .htaccess, and then grab the resulting variable in your code to display the page the way you want it.

I cheated to do mine. URL looks like http://www.mysite.com/20110311275/my-article.html the tail end of the date string contains the ID number of the article. In this case 275, the name of the html portion becomes the title for the page by using ucwords(). .htaccess outputs two variables id and title.

#RewriteRule ^([0-9]+)/([a-zA-Z0-9-]+).html$ /index.php?id=$1&title=$2 [L,nc]
×

Success!

Help @robertbarzyk 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

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