Saturday, February 4, 2017

note to self: custom pretty url path handling/redirect under apache

One popular trick is to make "pretty urls", so you can have something like
instead of

(On my site that's how I get stuff like working)

So, for reference to my future self, here's what you do:
In an .htaccess file in the webroot for the subdomain do something like

Options -Indexes
RewriteEngine On
RewriteRule ^band\/(.*)$ view.php?info=$1 [L]

And then a sample development view.php might start

$path = $_GET["info"];
$parts = explode("/",$path);
foreach($parts as $part){
  print "GOT ".$part."<br>";

You have options to do more work in the regex rather than in the script things land on, like if you want different levels of pathness to go to different files, but the syntax can be arcane.

No comments:

Post a Comment