In the end I am trying to get...
1
domain.com/games-A.html to redirect to => domain.com/games/a
domain.com/games-B.html to redirect to => domain.com/games/b
And so on... all the way to z.
The problem here is changing an upper case character to its lower case counterpart. Do you have access to the httpd.conf? If not, you won't have Apache's {toupper} function so you're stuck with a series of mod_alias or mod_rewrite statements.
2
domain.com/4578/air-tales.html to redirect => domain.com/games/a/air-tales
domain.com/654646577/blood.html to redirect => domain.com/games/b/blood
There is NO way for Apache to GUESS that b translated to 654646577. IMHO, that's not required, though, as you should be able to change the blood.html's underlying script (you ARE database driven, aren't you?) to fetch the blood field's name rather than the id.
3
domain.com/games-num.html to redirect to => domain.com/games/0-9
There is no way for Apache to know that num = 0-9, is there? Okay, that can be hard-coded but what are the other options?
4
domain.com/46544/2006-fifa-world-cup.html to redirect to => domain.com/games/0-9/2006-fifa-world-cup
Again, where in the world is Apache supposed to get 46544 from?
I'd really appreciate it if someone can point me in the right direction.
READ the mod_rewrite tutorial article linked in my signature - with emphasis on the Regex section.
Code:
# Start properly
RewriteEngine on
# If not a file
RewriteCond %{REQUEST_FILENAME} !-f
# AND if not a directory
RewriteCond %{REQUEST_FILENAME} !-d
# AND if not favicon.ico (=/ is dead wrong!)
RewriteCond %{REQUEST_URI} !=/favicon.ico
# Redirect FROM games-{zero to many of any character}.html
# to games/{zero to many of any character}
# Last means to terminate the mod_rewrite block,
# QSA is to retain any query string,
# NC (No Case) is irrelevant (TOTALLY worthless here) and
# R=301 says to make this a permenant redirection (SE's and display)
RewriteRule ^games-(.*).html$ /games/$1 [L,QSA,NC,R=301]
# Capture {zero to many of any character}/{one lower case character}
# -> {a different zero to many}.html and redirect to
# -> games/{sincle character}/{single character}{a different zero to many}
# -> with the same ridiculous set of flags
RewriteRule ^(.*)/([a-z])(.*).html$ /games/$2/$2$3 [L,QSA,NC,R=301]
# THEN redirect EVERYTHING to index.php as the value for q!
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
Bookmarks