Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2002

    Angry Tricky mod_rewrite question...

    Even with excellent documentation available to me, I consistently have trouble with mod_rewrite... Here's one that's causing me to pull my hair out. (As a nut about preserving anonymity for friends/clients, I'm going to pretend that my domain is, someone else got it--and that the URL in question is, sadly, not the case.)

    I run a Wordpress installation with several users. Users get, but WordPress does its magic such that /name never actually exists, but is just a "pretty" URL.

    So registered, and wants* to be* -- this sounds like an easy chore for mod_rewrite. But for whatever reason, I've spent hours making myself miserable trying to make this work, and it doesn't. Instead, Apache seems to throw itself into an infinite loop, skyrocket my load average until the machine just locks up and has to be rebooted.... (!)

    Part of the problem is that it's effectively a double-redirect, but this shouldn't be a problem. ( -> -> or whatnot)

    What am I doing wrong? I'm attaching my full .htaccess, in case one of the 'irrelevant' sections holds the key. Comments included for ease of reading:

    RewriteEngine On
    RewriteBase /
    # Rewrite all requests for / to /main2
    # This SHOULDN'T be affecting things, as it remaps
    # the main page of the site (a custom script) to
    # its ugly URL on the filesystem...
    RewriteCond %{HTTP_HOST} ^$
    RewriteRule ^()$ main2/ [NC,L]
    RewriteRule ^default.css$ main2/default.css [NC,L]
    RewriteRule ^images(/.*)?$ main2/images/$1
    RewriteRule ^search.php(.*)?$ main2/search.php$1
    # ->
    RewriteCond %{HTTP_HOST} ^(.*)$
    RewriteRule (.*) /kyle/$1 [,N]
    # A bit of code that's been eerily accurate in combatting
    # comment spam... At the end, I throw them a redirect
    # to a 1MB text file on 8080, which runs thttpd throttled
    # to 16 bytes/second... Whether this accomplishes anything
    # is irrelevant here. :-P
    ## No referer = no POST for you!
    ## Per
    RewriteCond %{REQUEST_METHOD} POST
    RewriteCond %{REQUEST_URI} .wp-comments-post\.php*
    RewriteCond %{HTTP_REFERER} !.** [OR]
    RewriteCond %{HTTP_USER_AGENT} ^$
    #RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]
    RewriteRule (.*)\:8080/20417.txt [NC,L]
    ### For WP Super Cache ##########
    RewriteCond %{QUERY_STRING} !.*s=.*
    RewriteCond %{HTTP_COOKIE} !^.*comment_author_.*$
    RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$
    RewriteCond %{HTTP_COOKIE} !^.*wp-postpass_.*$
    RewriteCond %{HTTP:Accept-Encoding} gzip
    RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1index.html.gz -f
    RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1index.html.gz [L]
    RewriteCond %{QUERY_STRING} !.*s=.*
    RewriteCond %{HTTP_COOKIE} !^.*comment_author_.*$
    RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$
    RewriteCond %{HTTP_COOKIE} !^.*wp-postpass_.*$
    RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1index.html -f
    RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1index.html [L]
    #uploaded files
    RewriteRule ^(.*/)?files/$ index.php [L]
    RewriteRule ^(.*/)?files/(.*) wp-content/blogs.php?file=$2 [L]
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule . - [L]
    RewriteRule  ^([_0-9a-zA-Z-]+/)?(wp-.*) $2 [L]
    RewriteRule  ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
    RewriteRule . index.php [L]
    Any help is greatly appreciated! This has been driving me nuts for weeks.

  2. #2
    Join Date
    Feb 2005
    Without looking at it in detail, you've got a couple of cases there with more than one RewriteRule following the RewriteCond(s). You can't do that (well, you can, but it won't work the way you expect ). Just use one RewriteRule at the end of each block, repeating the RewriteCond(s) as necessary.

    "Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts