DD,
PLEASE use the [noparse]
...
[/noparse] tags around your code! When you quote something (yes, even code), it’s removed from the quote when someone tries to respond to you.
Okay, the author really doesn’t know much about Apache servers nor mod_rewrite but you can gain some insight with the tutorial article linked in my signature.
First, I’m sure that you’ll agree that “pretty URLs” are, well, prettier than URLs with query strings attached. SEO’s tend to agree so that’s where redirecting (using mod_rewrite) comes into play.
[COLOR="Red"]<IfModule mod_rewrite.c>
# NEVER include this in a production environment as
# it simply repeats the test which should NOT be
# necessary if you are a webmaster and is SEVERELY
# abusive of the server to do so on EVERY request.[/COLOR]
# Simply confirm that it's enabled and get on with coding.
RewriteEngine on
# For sales:
RewriteRule ^shop/sales[COLOR="Red"]/?$[/COLOR] sales.php
# The trailing / is problematic, optional or not and
# (the end anchor is apparently irrelevant) because
# the browser can then look for relative links at two directory
# levels - NOT a good thing!
# For the primary categories:
RewriteRule ^shop/([A-Za-z\\+]+)/?$ shop.php?type=$1
# This is okay but, if you know the categories (types),
# then you can use them in a list like (type1|type2|...).
# Same comment as before about the /?$. Very bad coding!
# For specific products:
RewriteRule ^browse/([A-Za-z\\+\\-]+)/([A-Za-z\\+\\-]+)/([0-9]+)$ browse.php?type=$1&category=$2&id=$3
# The - does NOT get escaped in a range definition where it's
# normally a metacharacter because the exception is when it's
# listed first (or last).
# For HTTPS pages:
RewriteCond %{HTTPS} off
RewriteRule ^(checkout\\.php|billing\\.php|final\\.php|admin/(.*))$ https://%{HTTP_HOST}/$1 [R=301,L]
# This is an example of the selection list I described above.
# There were problems with {HTTPS} as it was originally
# on or null (it's now defined as 'on' or 'off') so the
# %{REMOTE_PORT} was matched against ^443$ which
# is used by secure servers.
# Tip: I'd use %{REQUEST_URI} rather than $1 because
# it has all the information available already. More typically
# used to replace $1 when it was captured with (.*) (to
# capture the entire URI - you have some limitations in your regex).
[COLOR="Red"]</IfModule>
# Same comment as above.[/COLOR]
1.) Isn’t that a complete contradiction to what he originally said?
No, what he left UNSAID is that the URI (except in the https redirection) will be left unchanged while Apache will go off to find the file it can serve (and provide it with the query string it needs to access the database for your type, category and product id).
2.) What constitutes a “pretty” URL?
“Pretty awful” is a URL with a query string attached, therefore, a “pretty URL” is something “human readable,” i.e., shop/chocolates.
3.) Which format do I really desire?
That depends completely upon you! Of course, if you’re trying to make a professional website, then you’d create “pretty” links (human readable - humans just can’t translate ids to a product) for your visitors. Since it also helps in SEO rankings, that’s a benefit for your website (client).
4.) How does the MOD_REWRITE go from shop/coffee to shop.php?type=coffee when…
# For the primary categories:
RewriteRule ^shop/([A-Za-z\\+]+)/?$ shop.php?type=$1
...is supposed to take shop/ plus one or more combination of characters that are A-Z, a-z, + and an optional "/" and put that where the $1 is at?!
That's the purpose of regular expressions (yes, you DO need to read the tutorial article). The () pair denotes an "atom" which is captured as a variable by mod_rewrite, specifically, $1. The [] pair denotes a character range definition with A-Z denoting uppercase letters, a-z all lowercase letters and the + (which, I don't believe, needs to be escaped either) denotes the + character. OUTSIDE the character range definition (which has specified ONE character of the range defined), the + means one or more of the preceding character (i.e., one or more of the range of defined characters).
I would expect things like shop.php?type=shop/Mugs or shop.php?type=shop/Mugs/ or shop.php?type=shop/coffee.
Sorry, shop was NOT in the () brackets nor the / for that matter.
Beyond belief? Nope! I think that the author you were reading didn't know much about what he was talking about (with respect to the mod_rewrite) so that he was unable to explain it to you.
mod_rewrite is a very powerful tool (ergo, M$ has tried to implement it for their IIS servers, too) which is based on a subset of regular expressions. With a little regex knowledge and a logical mind, you can create some very powerful redirections.
Regards,
DK