hello,

i was woundering if somone could point me in the right direction.
Im making a CMS/socialnetworking script for fun and want to change how the url gets the data for profiles.

at the moment its using the tradition $_GET thing from the broswer url, but id like to try and get it to do
(123 being the userid/username) similar to facebook and myspace.

however i have no idea what this parameter passing is called. Or even if it is parameter passing?

any ideas?

thanks it advance =)

Dani AI

Generated

Building on and : here are practical, copy-paste-ready ways to serve profile URLs like http://www.mysite.com/123, plus common gotchas.

A minimal Apache solution (.htaccess) that rewrites only non-file/non-directory requests and passes the number as id:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)/?$ /index.php?id=$1 [L,QSA]

An alternative if you prefer PHP routing (no rewrite available): read and parse the path, then route in a front controller:

$path = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/');
if (preg_match('#^([0-9]+)$#', $path, $m)) {
    $id = (int)$m[1];
    // load profile by $id
}

Practical tips:

  • Exclude existing files and directories (the two RewriteCond lines) so assets like /css/style.css still work.
  • Decide early whether you want numeric IDs (/123) or slugs (/john-doe). Patterns differ; pick one to avoid ambiguous routes.
  • Always validate/sanitize the extracted value and use prepared statements when querying the DB.
  • Reserve prefixes (e.g., /admin, /api, /assets) to avoid collisions with top-level profile paths.
  • For Nginx, use a similar rewrite ^/([0-9]+)/?$ /index.php?id=$1 last; or try_files with a front controller.
  • Consider 301 canonical redirects if old ?id=123 URLs must map to /123 for SEO.

These snippets are intentionally small so they slot into most CMS/front-controller setups.

Recommended Answers

All 2 Replies

URL Rewriting is what you want.

Your PHP script can stay the same, it can still get passed the Query String, all rewriting does is change how the user sees the URL in this case.

A Google of URL Rewrite will give you a multitude of guides :)

look for .htaccess on apache

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.