Down with mod_rewrite
(Information Technology,Programming)
There's this false idea in the web space that "pretty URLs" are preferred somehow. You know the kind I'm talking about--
http://mysite.com/some/thing/or/that
I'm not sure who prefers them. There used to be this idea that search engines preferred them. But I've researched it. Web spiders and search engines really don't care what your URL looks like (within reason).
I suppose a URL like this:
http://mysite.com?some=thing&or=that
might be more difficult for a person to copy one letter at a time into the browser's locator. But who's gonna do that? It's been years since I did anything like that. These days, I just highlight a link, copy and paste. So I really don't care what it looks like.
I used to work at a company which built and maintained web portals for a
variety of companies. The customers would request modifications to their
sites, and we'd log onto the internal copy of the site for that company.
We'd do the modifications and then test them locally. Problem was, they
used a huge amount of Apache mod_rewrite
code in their .htaccess
files. Someone would say, "It's on the page where you modify your
membership level". Okay, what page is that? Okay, I found it on the
website. So far so good. But the URL in the browser had nothing to do
with the page I needed to edit. Why? mod_rewrite
.
If you're not familiar with Apache's mod_rewrite
, it's a bunch of
configuration items you put in a file at the web root. The file's called
.htaccess
. It basically allows you to reroute the requests from one
page to another page. It allows you to turn the second example above
into something "prettier" like my first example. If you looked at my
first example above in your browser, what page would you imagine you'd
need to code? No telling with mod_rewrite on the job.
Codeigniter (I don't use it, but it really is a good framework) not only
recommends the use of mod_rewrite
, but they also have a whole
infrastructure for decoding the various segments of the URL. And of
course, as is the way of OOP, the router code figures out which
controller and then which method to execute.
My point is that there's a lot of confusing infrastructure involved in using "pretty" URLs, and it's really not necessary. I mean, what could be easier than:
// resolve parameters
$some = $_GET['some'] ?? NULL;
$or = $_GET['or'] ?? NULL;
// get data from model
$display_data = $model->some_func($some, $or);
// call the view
include 'viewfile';
You could do it the OOP way and call the controller method this way:
$some->$or
Personally, I prefer a landing page/page controller for each function,
rather than using index.php
as a front controller to send control to
an OOP controller method.
But that's just me.