The MU forums have moved to WordPress.org

mod_rewrite and custom 404 (5 posts)

  1. Haggertus
    Member
    Posted 15 years ago #

    I have a customer that needed to be able to be able to upload static html files to there wpmu site. I edited the .htaccess and added a rewrite rule:
    RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.html)$ files\/$2 [L]

    I think what I did was make anything ending in .html serve from the files directory for that blog. This is working.

    However, after putting this in my custom 404 page no longer works for anything ending in .html

    Any ideas?

    Here's my full .htaccess. I have the ErrorDocument set in the apache configs rather than the .htaccess.

    RewriteEngine On
    RewriteBase /
    
    #uploaded files
    RewriteRule ^(.*/)?files/$ index.php [L]
    RewriteCond %{REQUEST_URI} !.*wp-content/plugins.*
    RewriteRule ^(.*/)?files/(.*) wp-content/blogs.php?file=$2 [L]
    
    # add a trailing slash to /wp-admin
    RewriteCond %{REQUEST_URI} ^.*/wp-admin$
    RewriteRule ^(.+)$ $1/ [R=301,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]
    
    #Static HTML Rewrite Rule
    RewriteRule  ^([_0-9a-zA-Z-]+/)?(.*\.html)$ files\/$2 [L]
    
    RewriteRule . index.php [L]
    
    <IfModule mod_security.c>
    <Files async-upload.php>
    SecFilterEngine Off
    SecFilterScanPOST Off
    </Files>
    </IfModule>
  2. cafespain
    Member
    Posted 15 years ago #

    If the files (html) physically exist on the server then they are covered by this:

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d

    If you want them located in the fake files directory, then you need to edit the blogs.php file to look for html files as well.

    You don't need to touch the htaccess file.

  3. Haggertus
    Member
    Posted 15 years ago #

    thanks for the response.

    yes the html files physically exist on the server. they are in wp-content/blogs.dir/##/files. with the rewrite rule they show up as blog.com/blog/file.html. The rewrite rule is serving it that way.

    I checked the blogs.php file and it has
    'htm|html' => 'text/html',

    Am I missing something?

    Thanks!

  4. Haggertus
    Member
    Posted 15 years ago #

    Maybe I'm not looking at the right blogs.php file. I see 3 of them.
    /wp-admin/wpmu-blogs.php
    /wp-admin/blogs.php
    /wp-content/blogs.php

    I was looking in /wp-content/blogs.php.

    Thanks.

  5. Haggertus
    Member
    Posted 15 years ago #

    I bumped up the apache LogLevel to debug. Found this in the error log:

    Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

    So I am hitting a loop in my rewrite rule. Any one out there see what is causing it? my .htaccess is in the first post.

    Thanks.

About this Topic

  • Started 15 years ago by Haggertus
  • Latest reply from Haggertus