WordPress.org

Ready to get started?Download WordPress

Forums

mod_rewrite, vhosts, and the site root (6 posts)

  1. thefreefood
    Member
    Posted 9 years ago #

    I have a very thorny and strange problem with mod_rewrite. I am running my site as a virtual host with Apache (i.e. theirdomain.com/~me = mydomain.com). Normally, this works no problem. However, I have recently added permalink support using the WordPress wizard, so now my .htaccess looks like this:

    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /
    RewriteRule ^category/(.*)/(feed|rdf|rss|rss2|atom)/?$ /wp-feed.php?category_name=$1&feed=$2 [QSA]
    RewriteRule ^category/?(.*) /index.php?category_name=$1 [QSA]
    RewriteRule ^author/(.*)/(feed|rdf|rss|rss2|atom)/?$ /wp-feed.php?author_name=$1&feed=$2 [QSA]
    RewriteRule ^author/?(.*) /index.php?author_name=$1 [QSA]
    RewriteRule ^([0-9]{4})/?([0-9]{1,2})?/?([0-9]{1,2})?/?([_0-9a-z-]+)?/?([0-9]+)?/?$ /index.php?year=$1&monthnum=$2&day=$3&name=$4&page=$5 [QSA]
    RewriteRule ^([0-9]{4})/?([0-9]{1,2})/([0-9]{1,2})/([_0-9a-z-]+)/(feed|rdf|rss|rss2|atom)/?$ /wp-feed.php?year=$1&monthnum=$2&day=$3&name=$4&feed=$5 [QSA]
    RewriteRule ^([0-9]{4})/?([0-9]{1,2})/([0-9]{1,2})/([_0-9a-z-]+)/trackback/?$ /wp-trackback.php?year=$1&monthnum=$2&day=$3&name=$4 [QSA]
    RewriteRule ^feed/?([_0-9a-z-]+)?/?$ /wp-feed.php?feed=$1 [QSA]
    RewriteRule ^comments/feed/?([_0-9a-z-]+)?/?$ /wp-feed.php?feed=$1&withcomments=1 [QSA]

    And, in fact, rewriting works normally, with one BIG caveat. If I go to mydomain.com/index.php, I can access the site normally, but if I just type mydomain.com/ (with or without the trailing slash), I get an error 403. If I go to theirdomain.com/~me it works fine though. And as soon as I turn off RewriteEngine, it works normally, albeit without rewriting.
    So from what I can tell, it's an interaction between virtual hosts and mod_rewrite. I know that mod_rewrite is not turned on for the entire server or in my VirtualHost declaration. However, I'm not the server root, and I can't modify the conf files or view the error logs to get any more information. Any suggestions?

  2. Ozh
    Member
    Posted 9 years ago #

    tried to RewriteRule / /index.php ?

  3. thefreefood
    Member
    Posted 9 years ago #

    Yeah, I tried that one. No such luck.
    The only thing I've thought of trying that I haven't been able to do yet is putting RewriteEngine On in the VirtualHost declaration in httpd.conf. However, as I am not root, I have to wait until the sysadmin is available to try this. Also, I have no logical basis for trying this, since the Apache docs claim that the virtual host declaration is processed last. I'd love to hear more suggestions though, I'm getting pretty annoyed with this.

  4. Matt Mullenweg
    Troublemaker
    Posted 9 years ago #

    Could it be a DirectoryIndex problem?

  5. thefreefood
    Member
    Posted 9 years ago #

    I tried putting DirectoryIndex index.php in .htaccess, but that didn't work. The thing is, accessing the index works normally when I turn off the RewriteEngine, and it also works normally when I don't use the virtual host address. I also tried removing index.php to see if I could get a directory listing, but that didn't work (even with Options +Indexes set).
    I looked at the Apache docs, and it says that .htaccess commands are always executed first, and vhosts are executed last, so it seems strange that there would be an issue between the two. But I figure this is worth solving on this forum because a lot of people who want to use permalinks may not have the knowledge to troubleshoot a problem like this, and wouldn't be able to go through all these steps to find the answer, and we don't want them to be unable to use permalinks because of it.

  6. thefreefood
    Member
    Posted 9 years ago #

    After a whole lot of talking to people on #apache, experimenting, and testing, I managed to find the issue on this one. It turns out that the default install of my Apache server (Red Hat Enterprise) had a section of httpd.conf that looked like this:
    <LocationMatch "^/$">
    Options Multiviews
    ErrorDocument 403 error/noindex.html
    </LocationMatch>

    Essentially, this code was designed to prevent a file listing of the server index from ever being shown on the primary server. However, because <Location> and <LocationMatch> are used for directives based on URL path and not on physical path, this section applied also to all virtualhosts, but only for the site root, and effectively turned off FollowSymLinks in that instance only, causing the error 403 only then. I solved this problem by having the admin put a <Location> section inside my virtualhost declaration that gives FollowSymLinks privileges for my root explicitly, overriding the server default.
    I know this is an odd issue, one that has far more to do with Apache than with WordPress. However, I had this problem when installing WordPress "out of the box," and it took me more hours than I can count and a lot of learning about Apache to fix it. So people may want to be on the lookout for this sort of problem, so that they can spare folks the major trouble that I had to go through. Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.