WordPress Permalink Rewriting

Jun 30, 2008 at 2:14 AM
I have read all the other topics on this subject, but I can't seem to find an good answer for this. This is what I'm using right now:
RewriteRule ^/(?!index.php)(?!wp)(.*)$     /index.php/$1        [I]

However, I can't seem to access files like this:
http://www.domain.com/Files/Test.exe

How can I allow files with extensions to be ignored by this rule?
Coordinator
Jul 1, 2008 at 12:09 AM
I don't understand what you are asking.

Here's what I typically do in this situation.  I ask two questions;
 What are you seeing?  (by this I mean, in the browser, as well as in the IIRF log)
 What are you expecting to see?  (ditto)

Please try to be complete, and remember, I'm not on your computer so assume I'm a moron and I don't know what you're trying to do. 

You said "I can't seem to access files like this:  http://www.domain.com/Files/Test.exe".
Does that mean, any request that ends in an .exe ... is not satisfied?
something else?

I guess you are expecting the URL to be rewritten to something like 
http://www.domain.com/index.php/Files/Test.exe

What happens if you invoke that URL directly?

Something else to check:
There is a thing called URLscan which is often installed on IIS servers, sometimes as a part of the IISLockdown.exe tool.  UrlScan filters some known "bad" URLs like those ending in .exe. 
Is it possible that your request is being filtered by urlscan before ever reaching the IIRF?   If the IIRF logs show no log statements for the Test.exe request, then that is what is happening, I suspect.


Jul 1, 2008 at 5:22 PM
Sorry, I should have been more detailed. IIRF is the only ISAPI filter I currently have installed, and I only have this 1 rule in the IIRF configuration file:
RewriteRule ^/(?!index.php)(?!wp)(.*)$     /index.php/$1        [I]

Unfortunately, with this rule, all URLs get "/index.php/" inserted into it unless they start with "wp". This means if I have this file: "/Files/Test.exe", for example, I get a 404 error because IIRF changes it to "/index.php/Files/Test.exe". How can I avoid this? Is there any way to change the rule to only insert "index.php" if the requested URL doesn't have a file extension?

I want this to get rewritten:
/2008/06/my-blog-post/

But not these:
/Files/Test.exe
/Images/image.jpg

Thanks!
Coordinator
Jul 1, 2008 at 6:48 PM

JT, I am glad you said that if you send "/Files/Test.exe", IIRF changes it to "/index.php/Files/Test.exe". That is exactly what your rule tells IIRF to do. So it appears to be working.

You don't want the rule to apply if the original request has an extension. Ok, you nearly solved your problem yourself. you just need a regex that excludes extensions. How about:

RewriteRule ^/(?!index.php)(?!wp)([^\.]*)$     /index.php/$1        [I]

This just replaces the . (dot) in your original regex with [^\.] . The dot in regex-speak is a wildcard for "any character". I replaced that with a different expression. The regular expression language says that a string contained in square brackets [ ] indicates any one of a set of characters. Inside the square brackets the first char is a caret. Regex-speak says that a caret as the first char within square brackets indicates the negation of the set of characters. So that means it is any character NOT included in the set of chars that follows the caret. ya follow me? The set that follows the caret includes exactly one character, a dot. Except this is not the wildcard dot. I backslash-escaped it to indicate it is well-and-truly a dot, not a wildcard. So the square-bracket thing says "any character not including a dot". That matches any URL with no extension. Which is what I think you want. you have to try it to see if it works as you imagined.

This is why people say that the regular expression language is like a dark art .  It's not really .  It's just that the syntax is very obtuse and cryptic and hard-to-remember.
But once you get the idea, it's not difficult.

Jul 1, 2008 at 11:52 PM
Thanks - that worked like a champ. You're detailed description helped me get a few more rules working as well, thanks again!
Coordinator
Jul 2, 2008 at 6:28 AM
JT, it's all YOU.