Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2002
    Posts
    1,376

    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 fog.com--sadly, someone else got it--and that the URL in question is kyle.com--also, sadly, not the case.)

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

    So fog.com/kyle registered kyle.com, and wants kyle.com/* to be fog.com/kyle/* -- 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. (kyle.com/ -> fog.com/kyle -> fog.com/index.php?user=kyle 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:

    Code:
    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} ^fog.com$
    RewriteRule ^()$ main2/ [NC,L]
    RewriteRule ^default.css$ main2/default.css [NC,L]
    RewriteRule ^images(/.*)?$ main2/images/$1
    RewriteRule ^search.php(.*)?$ main2/search.php$1
    
    # kyle.com -> fog.com/kyle
    RewriteCond %{HTTP_HOST} ^(.*)kyle.com$
    RewriteRule (.*) /kyle/$1 [E=HTTP_HOST:fog.com,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 http://codex.wordpress.org/Combating_Comment_Spam/Denying_Access#Deny_Access_to_No_Referrer_Requests
    RewriteCond %{REQUEST_METHOD} POST
    RewriteCond %{REQUEST_URI} .wp-comments-post\.php*
    RewriteCond %{HTTP_REFERER} !.*fog.com.* [OR]
    RewriteCond %{HTTP_USER_AGENT} ^$
    #RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]
    RewriteRule (.*) http://fog.com\: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
    Location
    Australia
    Posts
    5,842
    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.
    Chris

    "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
  •