Web Hosting Talk







View Full Version : ModRewrite Rules: Tricky Question


RSMN
08-21-2008, 12:15 PM
I'm writing a url shortening app for my company, and I'm using mod_rewrite to parse the 5 digit code (ie. www.example.com/ASDFG (http://www.example.com/ASDFG)) and pass the code to a script.

I already have all the scripts written, my problem is that I also have pages such as www.example.com/admin.aspx (http://www.example.com/admin.aspx) and mod_rewrite is sending a code of "ADMIN" to the URL shortening script and not serving the actual page.

Does anyone have a rewrite rule that states if what comes after the first slash is 5 characters AND ONLY 5 characters, then to push it to that script?

Thanks for your help!

ThatScriptGuy
08-21-2008, 12:39 PM
What you should be doing in your .htaccess (Pseudo-code style) is this:


RewriteEngine On
if requested URL is not a file
if requested URL is not a directory
Pass code to script

RewriteCond %{REQUEST_FILENAME} !-f # Existing File
RewriteCond %{REQUEST_FILENAME} !-d # Existing Directory

Kevin

RSMN
08-21-2008, 12:55 PM
Wow. I knew that, but I just didn't put 2+2 together.

I really feel like an idiot now!


Thanks!