Rewrite rules not working with .htaccess but do with vhost - apache

I am a little miffed by this one, the rules I am pretty sure are correct yet when using them in a .htaccess file they just won't apply.
The rules push everything through a dispatch.php which then handles my MVC views and controllers for me.
//htaccess file - Accessing http://topaz.local/app/users/login
RewriteEngine On
RewriteCond %{REQUEST_URI} !dispatch/.php$
RewriteCond /var/www/topaz%{REQUEST_FILENAME} !-f
RewriteRule ^(/.*)$ /dispatch.php?url=$1 [L,QSA]
RewriteRule ^x/.!dispatch/.php([^b]+)!dispatch/.php$ !dispatch/.php [L,NE]
[topaz.local/sid#12a94f8][rid#1ee71b0/initial] [perdir C:/var/www/topaz/] add path info postfix: C:/var/www/topaz/app/users -> C:/var/www/topaz/app/users/login
[topaz.local/sid#12a94f8][rid#1ee71b0/initial] [perdir C:/var/www/topaz/] strip per-dir prefix: C:/var/www/topaz/app/users/login -> app/users/login
[topaz.local/sid#12a94f8][rid#1ee71b0/initial] [perdir C:/var/www/topaz/] applying pattern '^(/.*)$' to uri 'app/users/login'
[topaz.local/sid#12a94f8][rid#1ee71b0/initial] [perdir C:/var/www/topaz/] add path info postfix: C:/var/www/topaz/app/users -> C:/var/www/topaz/app/users/login
[topaz.local/sid#12a94f8][rid#1ee71b0/initial] [perdir C:/var/www/topaz/] strip per-dir prefix: C:/var/www/topaz/app/users/login -> app/users/login
[topaz.local/sid#12a94f8][rid#1ee71b0/initial] [perdir C:/var/www/topaz/] applying pattern '^x/.!dispatch/.php([^b]+)!dispatch/.php$' to uri 'app/users/login'
[topaz.local/sid#12a94f8][rid#1ee71b0/initial] [perdir C:/var/www/topaz/] pass through C:/var/www/topaz/app/users
Compared to the output via the vhost:
[topaz.local/sid#18374e8][rid#1868310/initial] init rewrite engine with requested uri /app/users/login
[topaz.local/sid#18374e8][rid#1868310/initial] applying pattern '^(/.*)$' to uri '/app/users/login'
[topaz.local/sid#18374e8][rid#1868310/initial] rewrite '/app/users/login' -> '/dispatch.php?url=/app/users/login'
[topaz.local/sid#18374e8][rid#1868310/initial] split uri=/dispatch.php?url=/app/users/login -> uri=/dispatch.php, args=url=/app/users/login
[topaz.local/sid#18374e8][rid#1868310/initial] local path result: /dispatch.php
[topaz.local/sid#18374e8][rid#1868310/initial] prefixed with document_root to C:/var/www/topaz/dispatch.php
[topaz.local/sid#18374e8][rid#1868310/initial] go-ahead with C:/var/www/topaz/dispatch.php [OK]

Related

Rewrite rules issue with two variables

I am trying to introduce two URL path rewrites but for some reason it does not work as expected.
I am trying to rewrite:
/styles/democlient/main.css to _projects/democlient/public/styles/main.css in the first instance. The second 'styles' rule works as expected, only the first one doesn't.
I added LogLevel alert rewrite:trace6 to my Apache vhosts configuration to make it easier to track. It seems to me that when mod is reaching the first 'style' rule then it does not stop and for some reason tries to match it to the second one.
My .htaccess
Options +FollowSymLinks
RewriteEngine on
RewriteRule styles/([a-z0-9]+)/(.*) _projects/$1/public/styles/$2 [NC,L]
RewriteRule styles/(.*) public/styles/$1 [NC,L]
RewriteRule (.*)/(.*) index.php?page=$1&subpage=$2 [NC,L,QSA]
RewriteRule (.*) index.php?page=$1 [NC,L,QSA]
My logtrack
[perdir E:/www/WEB_tech4rec/] add path info postfix: E:/www/WEB_tech4rec/styles -> E:/www/WEB_tech4rec/styles/democlient/main.css
[perdir E:/www/WEB_tech4rec/] strip per-dir prefix: E:/www/WEB_tech4rec/styles/democlient/main.css -> styles/democlient/main.css
[perdir E:/www/WEB_tech4rec/] applying pattern 'styles/([a-z0-9]+)/(.*)' to uri 'styles/democlient/main.css'
[perdir E:/www/WEB_tech4rec/] rewrite 'styles/democlient/main.css' -> '_projects/democlient/public/styles/main.css'
[perdir E:/www/WEB_tech4rec/] add per-dir prefix: _projects/democlient/public/styles/main.css -> E:/www/WEB_tech4rec/_projects/democlient/public/styles/main.css
[perdir E:/www/WEB_tech4rec/] strip document_root prefix: E:/www/WEB_tech4rec/_projects/democlient/public/styles/main.css -> /_projects/democlient/public/styles/main.css
[perdir E:/www/WEB_tech4rec/] internal redirect with /_projects/democlient/public/styles/main.css [INTERNAL REDIRECT]
[perdir E:/www/WEB_tech4rec/] strip per-dir prefix: E:/www/WEB_tech4rec/_projects/democlient/public/styles/main.css -> _projects/democlient/public/styles/main.css
[perdir E:/www/WEB_tech4rec/] applying pattern 'styles/([a-z0-9]+)/(.*)' to uri '_projects/democlient/public/styles/main.css'
[perdir E:/www/WEB_tech4rec/] strip per-dir prefix: E:/www/WEB_tech4rec/_projects/democlient/public/styles/main.css -> _projects/democlient/public/styles/main.css
[perdir E:/www/WEB_tech4rec/] applying pattern 'styles/(.*)' to uri '_projects/democlient/public/styles/main.css'
[perdir E:/www/WEB_tech4rec/] rewrite '_projects/democlient/public/styles/main.css' -> 'public/styles/main.css'
[perdir E:/www/WEB_tech4rec/] add per-dir prefix: public/styles/main.css -> E:/www/WEB_tech4rec/public/styles/main.css
[perdir E:/www/WEB_tech4rec/] strip document_root prefix: E:/www/WEB_tech4rec/public/styles/main.css -> /public/styles/main.css
[perdir E:/www/WEB_tech4rec/] internal redirect with /public/styles/main.css [INTERNAL REDIRECT]
[perdir E:/www/WEB_tech4rec/] strip per-dir prefix: E:/www/WEB_tech4rec/public/styles/main.css -> public/styles/main.css
[perdir E:/www/WEB_tech4rec/] applying pattern 'styles/([a-z0-9]+)/(.*)' to uri 'public/styles/main.css'
[perdir E:/www/WEB_tech4rec/] strip per-dir prefix: E:/www/WEB_tech4rec/public/styles/main.css -> public/styles/main.css[perdir E:/www/WEB_tech4rec/] applying pattern 'styles/(.*)' to uri 'public/styles/main.css'
[perdir E:/www/WEB_tech4rec/] rewrite 'public/styles/main.css' -> 'public/styles/main.css'
[perdir E:/www/WEB_tech4rec/] add per-dir prefix: public/styles/main.css -> E:/www/WEB_tech4rec/public/styles/main.css
[perdir E:/www/WEB_tech4rec/] initial URL equal rewritten URL: E:/www/WEB_tech4rec/public/styles/main.css [IGNORING REWRITE]
If you could help me find the reason, would be great.
You need to add a ^ before your styles RewriteRules and prevent your last RewriteRules to redirect physical files.
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^styles/([a-z0-9]+)/(.*) _projects/$1/public/styles/$2 [NC,L]
RewriteRule ^styles/(.*) public/styles/$1 [NC,L]
RewriteCond %{REQUEST_URI} !\.(jpg|png|css|js|php)$
RewriteRule (.*)/(.*) index.php?page=$1&subpage=$2 [NC,L,QSA]
RewriteCond %{REQUEST_URI} !\.(jpg|png|css|js|php)$
RewriteRule (.*) index.php?page=$1 [NC,L,QSA]

Difference in .htaccess behaviour

I have finished developing a micro app with Phalcon and tried to move it to production server, but have encountered some problems with .htaccess rules.
Directory layout on the serwer is like this :
/var/www
|- .htaccess
|- redmine/
|- wordpress/
|- (other dirs)
|- MyApp/
|- .htaccess
|- public/
|- .htaccess
|- api.php
/var/www/.htaccess :
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} !(redmine|MyApp) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
/var/www/MyApp/.htaccess :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !(\.gif|\.jpg|\.png|\.mp3|\.ods|\.csv|\.xls)$ [NC]
RewriteRule ^$ public/ [L]
RewriteCond %{REQUEST_URI} !(\.gif|\.jpg|\.png|\.mp3|\.ods|\.csv|\.xls)$ [NC]
RewriteRule (.*) public/$1 [L]
</IfModule>
/var/www/MyApp/public/.htaccess :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ api.php?_url=/$1 [QSA,L]
</IfModule>
I'm really new to all this. The top-most .htaccess was not setup by me, and frankly I don't know what is going on in there. The others are based on Phalcon tutorials.
Everything worked on my local machine, but stopped when I uploaded it. I turned on logging in both places.
Local log :
[perdir /Users/Losiowaty/MyApp/] add path info postfix: /Users/Losiowaty/MyApp/api -> /Users/Losiowaty/MyApp/api/poeci
[perdir /Users/Losiowaty/MyApp/] strip per-dir prefix: /Users/Losiowaty/MyApp/api/poeci -> api/poeci
[perdir /Users/Losiowaty/MyApp/] applying pattern '^$' to uri 'api/poeci'
[perdir /Users/Losiowaty/MyApp/] add path info postfix: /Users/Losiowaty/MyApp/api -> /Users/Losiowaty/MyApp/api/poeci
[perdir /Users/Losiowaty/MyApp/] strip per-dir prefix: /Users/Losiowaty/MyApp/api/poeci -> api/poeci
[perdir /Users/Losiowaty/MyApp/] applying pattern '(.*)' to uri 'api/poeci'
[perdir /Users/Losiowaty/MyApp/] RewriteCond: input='/MyApp/api/poeci' pattern='!(\\.gif|\\.jpg|\\.png|\\.mp3|\\.ods|\\.csv|\\.xls)$' [NC] => matched
[perdir /Users/Losiowaty/MyApp/] rewrite 'api/poeci' -> 'public/api/poeci'
[perdir /Users/Losiowaty/MyApp/] add per-dir prefix: public/api/poeci -> /Users/Losiowaty/MyApp/public/api/poeci
[perdir /Users/Losiowaty/MyApp/] strip document_root prefix: /Users/Losiowaty/MyApp/public/api/poeci -> /MyApp/public/api/poeci
[perdir /Users/Losiowaty/MyApp/] internal redirect with /MyApp/public/api/poeci [INTERNAL REDIRECT]
[perdir /Users/Losiowaty/MyApp/public/] add path info postfix: /Users/Losiowaty/MyApp/public/api -> /Users/Losiowaty/MyApp/public/api/poeci
[perdir /Users/Losiowaty/MyApp/public/] strip per-dir prefix: /Users/Losiowaty/MyApp/public/api/poeci -> api/poeci
[perdir /Users/Losiowaty/MyApp/public/] applying pattern '^(.*)$' to uri 'api/poeci'
[perdir /Users/Losiowaty/MyApp/public/] RewriteCond: input='/Users/Losiowaty/MyApp/public/api' pattern='!-d' => matched
[perdir /Users/Losiowaty/MyApp/public/] RewriteCond: input='/Users/Losiowaty/MyApp/public/api' pattern='!-f' => matched
[perdir /Users/Losiowaty/MyApp/public/] rewrite 'api/poeci' -> 'api.php?_url=/api/poeci'
split uri=api.php?_url=/api/poeci -> uri=api.php, args=_url=/api/poeci
[perdir /Users/Losiowaty/MyApp/public/] add per-dir prefix: api.php -> /Users/Losiowaty/MyApp/public/api.php
[perdir /Users/Losiowaty/MyApp/public/] strip document_root prefix: /Users/Losiowaty/MyApp/public/api.php -> /MyApp/public/api.php
[perdir /Users/Losiowaty/MyApp/public/] internal redirect with /MyApp/public/api.php [INTERNAL REDIRECT]
[perdir /Users/Losiowaty/MyApp/public/] strip per-dir prefix: /Users/Losiowaty/MyApp/public/api.php -> api.php
[perdir /Users/Losiowaty/MyApp/public/] applying pattern '^(.*)$' to uri 'api.php'
[perdir /Users/Losiowaty/MyApp/public/] RewriteCond: input='/Users/Losiowaty/MyApp/public/api.php' pattern='!-d' => matched
[perdir /Users/Losiowaty/MyApp/public/] RewriteCond: input='/Users/Losiowaty/MyApp/public/api.php' pattern='!-f' => not-matched
[perdir /Users/Losiowaty/MyApp/public/] pass through /Users/Losiowaty/MyApp/public/api.php
Remote log :
[perdir /var/www/MyApp/] add path info postfix: /var/www/MyApp/api -> /var/www/MyApp/api/poeci
[perdir /var/www/MyApp/] strip per-dir prefix: /var/www/MyApp/api/poeci -> api/poeci
[perdir /var/www/MyApp/] applying pattern '^$' to uri 'api/poeci'
[perdir /var/www/MyApp/] add path info postfix: /var/www/MyApp/api -> /var/www/MyApp/api/poeci
[perdir /var/www/MyApp/] strip per-dir prefix: /var/www/MyApp/api/poeci -> api/poeci
[perdir /var/www/MyApp/] applying pattern '(.*)' to uri 'api/poeci'
[perdir /var/www/MyApp/] RewriteCond: input='/MyApp/api/poeci' pattern='!(\\.gif|\\.jpg|\\.png|\\.mp3|\\.ods|\\.csv|\\.xls)$' [NC] => matched
[perdir /var/www/MyApp/] rewrite 'api/poeci' -> 'public/api/poeci'
[perdir /var/www/MyApp/] add per-dir prefix: public/api/poeci -> /var/www/MyApp/public/api/poeci
[perdir /var/www/MyApp/] strip document_root prefix: /var/www/MyApp/public/api/poeci -> /MyApp/public/api/poeci
[perdir /var/www/MyApp/] internal redirect with /MyApp/public/api/poeci [INTERNAL REDIRECT]
[perdir /var/www/MyApp/public/] add path info postfix: /var/www/MyApp/public/api.php -> /var/www/MyApp/public/api.php/poeci
[perdir /var/www/MyApp/public/] strip per-dir prefix: /var/www/MyApp/public/api.php/poeci -> api.php/poeci
[perdir /var/www/MyApp/public/] applying pattern '^(.*)$' to uri 'api.php/poeci'
[perdir /var/www/MyApp/public/] RewriteCond: input='/var/www/MyApp/public/api.php' pattern='!-d' => matched
[perdir /var/www/MyApp/public/] RewriteCond: input='/var/www/MyApp/public/api.php' pattern='!-f' => not-matched
[perdir /var/www/MyApp/public/] pass through /var/www/MyApp/public/api.php
[perdir /var/www/MyApp/public/] add path info postfix: /var/www/MyApp/public/api.php -> /var/www/MyApp/public/api.php/poeci
[perdir /var/www/MyApp/public/] strip per-dir prefix: /var/www/MyApp/public/api.php/poeci -> api.php/poeci
[perdir /var/www/MyApp/public/] applying pattern '^(.*)$' to uri 'api.php/poeci'
[perdir /var/www/MyApp/public/] RewriteCond: input='/var/www/MyApp/public/api.php' pattern='!-d' => matched
[perdir /var/www/MyApp/public/] RewriteCond: input='/var/www/MyApp/public/api.php' pattern='!-f' => not-matched
[perdir /var/www/MyApp/public/] pass through /var/www/MyApp/public/api.php
[perdir /var/www/] strip per-dir prefix: /var/www/poeci -> poeci
[perdir /var/www/] applying pattern '^index\\.php$' to uri 'poeci'
[perdir /var/www/] strip per-dir prefix: /var/www/poeci -> poeci
[perdir /var/www/] applying pattern '.' to uri 'poeci'
[perdir /var/www/] RewriteCond: input='/poeci' pattern='!(redmine|MyApp)' [NC] => matched
[perdir /var/www/] RewriteCond: input='/var/www/poeci' pattern='!-f' => matched
[perdir /var/www/] RewriteCond: input='/var/www/poeci' pattern='!-d' => matched
[perdir /var/www/] rewrite 'poeci' -> '/index.php'
[perdir /var/www/] trying to replace prefix /var/www/ with /
[perdir /var/www/] internal redirect with /index.php [INTERNAL REDIRECT]
The differences begin with the first line with [perdir (...)] ending with /public/. I don't understand why it adds .php and why the !-f rule doesn't match on the remote server.
Local server :
OSX 10.9.3, MAMP 3.0.4, Apache 2.2.26
Remote server :
Debian GNU/Linux 6.0.9, Apache 2.2.16
I wonder whether this is caused by the additional .htaccess file on the remote, or by the difference in Apache version.
I'd appreciate some explanation as to what's going on and any directions on where to look for answers.
Cheers!
This looks like it may be caused by multiviews. In both htaccess files inside MyApp, add this (above your rules, but anywhere is fine):
Options -Multiviews
Note that because api.php exists, a PATH INFO url like: /MyApp/api.php/something will fail the !-f check.

Why doesn't the RewriteCond prevent the RewriteRule from processing?

I've got the following in my .conf file used for cache busting js:
<Directory "/www/virtual/site/html/js/">
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^\d+\/(.+)$ $1 [L]
</Directory>
The idea here is to rewrite site.com/js/123456/script.js to site.com/js/script.js
(The rewriting works just fine)
If I look at the rewrite log the part I'm not understanding is that it is applying the RewriteRule to the script after the interal redirect... Shouldn't the %{REQUEST_FILENAME} !-f prevent it from processing the RewriteRule since the file exists?
Rewrite Log
[rid#2b607f8f2dc8/initial] (3) [perdir /www/virtual/site2/html/js/] add path info postfix: /www/virtual/site2/html/js/1234 -> /www/virtual/site2/html/js/1234/script.js
[rid#2b607f8f2dc8/initial] (3) [perdir /www/virtual/site2/html/js/] strip per-dir prefix: /www/virtual/site2/html/js/1234/script.js -> 1234/script.js
[rid#2b607f8f2dc8/initial] (3) [perdir /www/virtual/site2/html/js/] applying pattern '^\d+\/(.+)$' to uri '1234/script.js'
[rid#2b607f8f2dc8/initial] (2) [perdir /www/virtual/site2/html/js/] rewrite '1234/script.js' -> 'script.js'
[rid#2b607f8f2dc8/initial] (3) [perdir /www/virtual/site2/html/js/] add per-dir prefix: script.js -> /www/virtual/site2/html/js/script.js
[rid#2b607f8f2dc8/initial] (2) [perdir /www/virtual/site2/html/js/] strip document_root prefix: /www/virtual/site2/html/js/script.js -> /js/script.js
[rid#2b607f8f2dc8/initial] (1) [perdir /www/virtual/site2/html/js/] internal redirect with /js/script.js [INTERNAL REDIRECT]
[rid#2b6073eb14a8/initial/redir#1] (3) [perdir /www/virtual/site2/html/js/] strip per-dir prefix: /www/virtual/site2/html/js/script.js -> script.js
[rid#2b6073eb14a8/initial/redir#1] (3) [perdir /www/virtual/site2/html/js/] applying pattern '^\d+\/(.+)$' to uri 'script.js'
[rid#2b6073eb14a8/initial/redir#1] (1) [perdir /www/virtual/site2/html/js/] pass through /www/virtual/site2/html/js/script.js
mod_rewrite (by design) keeps on applying rewrite-rules, till the url no longer changes.
So the first time it rewrite 1234/script.js to script.js the second time it tries to apply the rule, the pattern regular expression doesn't match and script.js is 'passed through'.
This is the way it is supposed to work. It can sometimes be a pain, but it makes mod_rewrite a lot more powerful/useful.
edit
mod_rewite first tests the RewriteRule pattern, before trying to apply the RewriteCond's. This is so you can use backreferences $0, $1 etc. in your RewriteCond. After all the RewriteCond's it will create the substitution string, so it can also use backrefereces %0, %1. etc. See also the diagram below.
So this is why it tried to apply the pattern before testing if the file exists.

Any idea why this mod_rewrite rule isn't matching, I think it should be

My ubuntu localhost mod_rewrite is acting funky. I'm trying to rewrite the url:
mydomain.com/random/50/post-title-here/
to:
mydomain.com/random.php?id=50
using the rewrite rule:
Options -MultiViews
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^random/([0-9]+)$ random.php?id=$1
I can't for the life of me see how that simple rule could be matched wrong, but it just isn't working as you can see from the rewrite log that I've cleaned up and presented here.
RewriteCond: input='www.mydomain.com' pattern='^mydomain\.com$' [NC] => not-matched
127.0.0.1 - - [11/Oct/2011:11:12:44 --0500] [www.mydomain.com/sid#b7a4fc90][rid#b7c0f340/initial/redir#1] (1) [perdir /var/www/] pass through /var/www/rewrite.php
add path info postfix: /var/www/random -> /var/www/random/7960/we-serve-up-phat-beets-at-my-house/
strip per-dir prefix: /var/www/random/7960/we-serve-up-phat-beets-at-my-house/ -> random/7960/we-serve-up-phat-beets-at-my-house/
applying pattern '^random/([0-9]+)$' to uri 'random/7960/we-serve-up-phat-beets-at-my-house/'
add path info postfix: /var/www/random -> /var/www/random/7960/we-serve-up-phat-beets-at-my-house/
strip per-dir prefix: /var/www/random/7960/we-serve-up-phat-beets-at-my-house/ -> random/7960/we-serve-up-phat-beets-at-my-house/
applying pattern '^link([^/]*).html$' to uri 'random/7960/we-serve-up-phat-beets-at-my-house/'
add path info postfix: /var/www/random -> /var/www/random/7960/we-serve-up-phat-beets-at-my-house/
strip per-dir prefix: /var/www/random/7960/we-serve-up-phat-beets-at-my-house/ -> random/7960/we-serve-up-phat-beets-at-my-house/
applying pattern '^(.*)$' to uri 'random/7960/we-serve-up-phat-beets-at-my-house/'
RewriteCond: input='mydomain.com' pattern='^mydomain\.com$' [NC] => matched
rewrite 'random/7960/we-serve-up-phat-beets-at-my-house/' -> 'http://www.mydomain.com/random/7960/we-serve-up-phat-beets-at-my-house/'
explicitly forcing redirect with http://www.mydomain.com/random/7960/we-serve-up-phat-beets-at-my-house/
trying to replace prefix /var/www/ with /
escaping http://www.mydomain.com/random/7960/we-serve-up-phat-beets-at-my-house/ for redirect
redirect to http://www.mydomain.com/random/7960/we-serve-up-phat-beets-at-my-house/ [REDIRECT/301]
add path info postfix: /var/www/random -> /var/www/random/7960/we-serve-up-phat-beets-at-my-house/
strip per-dir prefix: /var/www/random/7960/we-serve-up-phat-beets-at-my-house/ -> random/7960/we-serve-up-phat-beets-at-my-house/
applying pattern '^random/([0-9]+)$' to uri 'random/7960/we-serve-up-phat-beets-at-my-house/'
add path info postfix: /var/www/random -> /var/www/random/7960/we-serve-up-phat-beets-at-my-house/
strip per-dir prefix: /var/www/random/7960/we-serve-up-phat-beets-at-my-house/ -> random/7960/we-serve-up-phat-beets-at-my-house/
applying pattern '^link([^/]*).html$' to uri 'random/7960/we-serve-up-phat-beets-at-my-house/'
add path info postfix: /var/www/random -> /var/www/random/7960/we-serve-up-phat-beets-at-my-house/
strip per-dir prefix: /var/www/random/7960/we-serve-up-phat-beets-at-my-house/ -> random/7960/we-serve-up-phat-beets-at-my-house/
applying pattern '^(.*)$' to uri 'random/7960/we-serve-up-phat-beets-at-my-house/'
RewriteCond: input='www.mydomain.com' pattern='^mydomain\.com$' [NC] => not-matched
pass through /var/www/random
Any ideas stack?
The $ meta-character means "assert end of subject", so your URL will not match unless it doesn't have anything else after the digits.

Mod_rewrite: Ruleset causes strange split and append in rewrite log

What causes the querystring to be split out and what
causes /news/50 to be appended in the second run (as an effect of the next flag N).
The behaviour I'm after is to rewrite /about/news/50/ to /about/news/news-item?post_id=50.
I add the N flag since I want to send the rewritten uri /about/news/news-item?post_id=50 to index.php.
I have the following rules in my .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule %{REQUEST_FILENAME} !-f
RewriteRule %{REQUEST_FILENAME} !-d
RewriteRule ^about/news/(\d+)/$ /about/news/news-item?post_id=$1 [QSA,N]
RewriteRule ^index\.php$ - [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [QSA,L]
</IfModule>
The log entries:
(2) init rewrite engine with requested uri /about/news/50/
(1) pass through /about/news/50/
(3) add path info postfix: /wordpress/about -> /wordpress/about/news/50/
(3) strip per-dir prefix: /wordpress/about/news/50/ -> about/news/50/
(3) applying pattern '%{REQUEST_FILENAME}' to uri 'about/news/50/'
(3) add path info postfix: /wordpress/about -> /wordpress/about/news/50/
(3) strip per-dir prefix: /wordpress/about/news/50/ -> about/news/50/
(3) applying pattern '%{REQUEST_FILENAME}' to uri 'about/news/50/'
(3) add path info postfix: /wordpress/about -> /wordpress/about/news/50/
(3) strip per-dir prefix: /wordpress/about/news/50/ -> about/news/50/
(3) applying pattern '^about/news/(\d+)/$' to uri 'about/news/50/'
(2) rewrite 'about/news/50/' -> '/about/news/news-item?post_id=50'
(3) split uri=/about/news/news-item?post_id=50 -> uri=/about/news/news-item, args=post_id=50
(3) add path info postfix: /about/news/news-item -> /about/news/news-item/news/50/
(3) applying pattern '%{REQUEST_FILENAME}' to uri '/about/news/news-item/news/50/'
(3) add path info postfix: /about/news/news-item -> /about/news/news-item/news/50/
(3) applying pattern '%{REQUEST_FILENAME}' to uri '/about/news/news-item/news/50/'
(3) add path info postfix: /about/news/news-item -> /about/news/news-item/news/50/
(3) applying pattern '^about/news/(\d+)/$' to uri '/about/news/news-item/news/50/'
(3) add path info postfix: /about/news/news-item -> /about/news/news-item/news/50/
(3) applying pattern '^index\.php$' to uri '/about/news/news-item/news/50/'
(3) add path info postfix: /about/news/news-item -> /about/news/news-item/news/50/
(3) applying pattern '.' to uri '/about/news/news-item/news/50/'
(4) RewriteCond: input='/about/news/news-item' pattern='!-f' => matched
(4) RewriteCond: input='/about/news/news-item' pattern='!-d' => matched
(2) rewrite '/about/news/news-item/news/50/' -> '/index.php'
(2) trying to replace prefix /wordpress/ with /
(1) internal redirect with /index.php [INTERNAL REDIRECT]
(2) init rewrite engine with requested uri /index.php
(1) pass through /index.php
(3) strip per-dir prefix: /wordpress/index.php -> index.php
(3) applying pattern '%{REQUEST_FILENAME}' to uri 'index.php'
(3) strip per-dir prefix: /wordpress/index.php -> index.php
(3) applying pattern '%{REQUEST_FILENAME}' to uri 'index.php'
(3) strip per-dir prefix: /wordpress/index.php -> index.php
(3) applying pattern '^about/news/(\d+)/$' to uri 'index.php'
(3) strip per-dir prefix: /wordpress/index.php -> index.php
(3) applying pattern '^index\.php$' to uri 'index.php'
(1) pass through /wordpress/index.php
Try the DPI (Discard PATH_INFO flag) if you rewrite a URL that had PATH_INFO stripped from it and don't want it added back on. It's a problem with per-directory rewrites
edit: if you do this, since wordpress counts on the PATH_INFO, you'd have to actually rewrite to /index.php/about/news/... to let the next round still see PATH_INFO.
RewriteRule ^about/news/(\d+)/$ /index.php/about/news/news-item?post_id=$1 [DPI,L]
instead of
RewriteRule ^about/news/(\d+)/$ index.php [DPI,L]