WordPress.org

Support

Support » How-To and Troubleshooting » Can’t get WP 1.5 to write proper .htaccess rules

Can’t get WP 1.5 to write proper .htaccess rules

  • This may have been discussed before, but I wasn’t able to find a solution.

    I have a blog that is located in the root of a domain, at least to the eye of the user. However, the WordPress files are located in a sub-directory. Now I’m having troubles with upgrading to 1.5. When WordPress 1.5 modifies the .htaccess file, it always creates rules that expect the WordPress index.php to be in the root of the domain, causing the whole thing fail.

    Here’s my setup:

    WordPress address: http://www.visakopu.net/wordpress
    Blog address: http://www.visakopu.net
    Permalink structure: /weblog/%year%/%monthnum%/%day%/%postname%/
    Category base: [empty]

    Sample of the .htaccess written by WordPress:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ – [S=35]
    RewriteRule ^feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?&feed=$1 [QSA,L]

    This is how I’ve got it working properly: (note that I’ve added the name of the sub-directory before /index.php)

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ – [S=35]
    RewriteRule ^feed/(feed|rdf|rss|rss2|atom)/?$ /wordpress/index.php?&feed=$1 [QSA,L]

    I know I can fix the rules manually and chmod the .htaccess file so that WordPress can’t write to it, but it’s not a real solution, is it?

Viewing 13 replies - 1 through 13 (of 13 total)
  • NuclearMoose
    Member

    @nuclearmoose

    Hmm. Interesting. Maybe you have found a bug? I’m not familiar with doing rewrite rules. I just get WordPress to do it for me and it works just fine!

    Check out http://mosquito.wordpress.org/ to see if there is a similar issue logged for this. I’m not in a position to offer you much help on this problem, roxeteer. Sorry.

    I have my site in a subdirectory, but I have the server redirects and stuff set up for that. My files are in /folder/folder/blog/ but the URIs I have for both the web address and blog address is simply http://blog.nuclearmoose.ca. Do you have some kind of redirect set up on your server that is maybe causing a problem? Maybe you DON’T have a redirect set up properly. I’m only guessing, however. As I said, this is an area that I am happy to let WordPress handle for me.

    I don’t have any other redirects set up in the .htaccess file. As far as I can see, mod_rewrite is doing as it’s supposed to do, it’s just that WordPress gives it wrong directions.

    WP puts rewrite rules in the blog address directory, not the WordPress address directory.

    Yes, these rules are written into /.htaccess. There’s no /wordpress/.htaccess. However, the point here is that the location of index.php should be taken into consideration when writing the mod_rewrite rules.

    There should not be a /wordpress/.htacces. /.htaccess should use /index.php not /wordpress/index.php. Everything is done in the Blog Address directory. The WordPress Address is not public and thus not used for rewrite rules or public URIs.

    Yes, and the index.php is located in the WordPress Address (http://www.visakopu.net/wordpress/index.php). After rewriting the URL, Apache tries to access /index.php (http://www.visakopu.net/index.php) which is wrong place to go.

    If your Blog Address is http://www.visakopu.net then http://www.visakopu.net/index.php is indeed the right place to go. If you don’t want it to go there, set your blog address to something else.

    So there’s no way to have WordPress files in a sub-directory? If I set Blog Address to http://www.visakopu.net/wordpress then WordPress writes the .htaccess file there and accessing the domain root doesn’t reach the rewrite rules.

    Just to clarify, when you go to Options -> General you’ll see there’s two addresses – one for your WP install and one for your blog. So you can install WP files to visakopu.net/wordpress and still have your blog at visakopu.net/. Your .htaccess rules will be written to your blog address (visakopu.net/)

    Make sure you have an index.php at visakopu.net! Copy the one from /wordpress to / and change the line
    require('./wp-blog-header.php'); to reflect your WP directory

    require('./wordpress/wp-blog-header.php'); Then all your rewrite rules will access the / directory, be picked up by the index.php there and be sent on to the WP admin files.

    Thanks, Ming. That will probably solve my problem in a clean-ish way. Although it’d be cleaner if one could be able to set the sub-directory name in the options and all WordPress files would reside in the same directory.

    Ditto — this worked for me. I had tried like crazy to set up a rewrite, redirectmatch, and alias all to no avail. I just don’t have the time right now to sift it all out.

    thanks

    Making a copy of index.php to the root did indeed do the trick.

    However, wp-feed.php doesn’t work with a setup like that. You need to add dirname(__FILE__) before each included file’s name to make it work again. I’ve created a bug report about it: http://mosquito.wordpress.org/view.php?id=1169

    Sorry folks. I didn’t opt for these options as it’s still messy and removes some of the functionality of WordPress and my templates. Instead, I did the following (using WP 1.5.2):

    WARNING: THIS IS A QUICK & NASTY WORK-AROUND THAT DOES THE JOB

    1. Install and setup WP so that the WordPress URI and the Blog URI point to the WP install directory – eg http://www.domain.com/wordpress/

    2. Edit the wp-includes/classes.php file and comment out lines 1244, 1245, 1246 and 1248 thus leaving it looking as follows:


    // if (strstr($query, $this->index)) {
    // $rules .= 'RewriteRule ^' . $match . ' ' . $home_root . $query . " [QSA,L]n";
    // } else {
    $rules .= 'RewriteRule ^' . $match . ' ' . $site_root . $query . " [QSA,L]n";
    // } }

    3. Go to Option -> General
    4. Set Blog Address to your base URI – eg http://www.domain.com
    5. Click Update Options. This should now create your .htaccess in the base directory of your site, not in /wordpress/
    6. Edit the new .htaccess file, and add the following BEFORE the
    # BEGIN WordPress line:

    RewriteRule ^$ /wordpress/ [QSA,L]

    Thus making the beginning of your file look as follows:

    RewriteRule ^$ /wordpress/ [QSA,L]
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d

    Note, you can change the /wordpress/ to where ever you chose to install WP.

    7. Save the file.

    You should find that all your RewriteRules point to /wordpress/index.php and it will stay this way when you make any updates in the future.

    Just one word of warning... these changes will be lost when you update WP to a later release (cos you're over-writing the classes.php file), but it's a small price to pay for neat, tidy convenience.

    I could have coded round this, but I really couldn't be arsed. Commenting out 3 lines is way simpler.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Can’t get WP 1.5 to write proper .htaccess rules’ is closed to new replies.