.htaccess - URL rewriting with PHP -
i have url looks like:
url.com/picture.php?id=51
how go converting url to:
picture.php/some-text-goes-here/51
i think wordpress same.
how go making friendly urls in php?
you can 2 ways:
the .htaccess route mod_rewrite
add file called .htaccess
in root folder, , add this:
rewriteengine on rewriterule ^/?some-text-goes-here/([0-9]+)$ /picture.php?id=$1
this tell apache enable mod_rewrite folder, , if gets asked url matching regular expression rewrites internally want, without end user seeing it. easy, inflexible, if need more power:
the php route
put following in .htaccess instead:
fallbackresource index.php
this tell run index.php
files cannot find in site. in there can example:
$path = ltrim($_server['request_uri'], '/'); // trim leading slash(es) $elements = explode('/', $path); // split path on slashes if(empty($elements[0])) { // no path elements means home showhomepage(); } else switch(array_shift($elements)) // pop off first item , switch { case 'some-text-goes-here': showpicture($elements); // passes rest of parameters internal function break; case 'more': ... default: header('http/1.1 404 not found'); show404error(); }
this how big sites , cms-systems it, because allows far more flexibility in parsing urls, config , database dependent urls etc. sporadic usage hardcoded rewrite rules in .htaccess
fine though.