0

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?

Gumbo
  • 643,351
  • 109
  • 780
  • 844
billmalarky
  • 920
  • 2
  • 12
  • 34

1 Answers1

1

The $ meta-character means "assert end of subject", so your URL will not match unless it doesn't have anything else after the digits.

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
  • HOLY MOTHER OF MARY! SOLVED! I have been ripping my hair out for a few days on this now. Yes it might seem stupid that I would have overlooked that rule, but my original rule was RewriteRule ^random/([0-9]+)/(.*)$ random.php?id=$1 and that would work on my actual webserver, but not on my local install. Well thanks to this post http://stackoverflow.com/questions/286004/hidden-features-of-mod-rewrite I had disabled multiviews via Options -MultiViews. That was my true problem, but by that point I had ripped up my rewrite rule so much that I created a new one (that you just fixed for me!) – billmalarky Oct 11 '11 at 16:54
  • After reading my comment, I just wanted to make it clear to anyone else dealing with this issue that I needed to disable multiviews for mod_rewrite to work, not enable (why the hell is multiviews set to on as a default? Seems like a terrible function...) – billmalarky Oct 11 '11 at 16:56