I am trying to use mod rewrite to remove and replace part of my url. I am looking to get my urls looking like this.
http://domain.com/e813c697e8dd8dc2bbfecb1d20b15783.html
instead of
http://domain.com/lookup.php?md5=e813c697e8dd8dc2bbfecb1d20b15783
lookup.php calls matches the md5 to the database and fetches and forwards you to the correct url.
All I need to do now is rewrite it so that it rewrites from this
http://domain.com/lookup.php?md5=e813c697e8dd8dc2bbfecb1d20b15783
to this
http://domain.com/e813c697e8dd8dc2bbfecb1d20b15783.html
I have tried this which works but it makes rewrites from any .html page at root level and makes it display nothing “blank”.
RewriteRule ^([a-z0-9]+)\.html$ /lookup.php?md5=$1
Can anyone tell me a way to do this so that my regular html pages are not messed up and be able to display these links how I want to? Thanks.
Your current rule is a way too broad. You need to make it more specific to only match md5 hash value — which is easy:
Your pattern for file name is too broad — it will match any file with letters and digits. md5 hash, on another hand, uses very limited subset of characters (
a-fonly) and digits .. and has to be 32 characters long. This pattern([a-f0-9]{32})does the job perfectly.I have also added
LandQSAflags (QSAto preserve any existing query string (like, tracking info, for example) andLto stop matching any other rules).To further ensure that it does not match any real files which may have name in such format (who knows), add
RewriteCond %{REQUEST_FILENAME} !-fline before the rule.