WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Blogger permalink RewriteRule not working (9 posts)

  1. gpaciga
    Member
    Posted 7 years ago #

    Hello.

    I've just imported from Blogger and am trying to set it up so that links to the old Blogger pages will redirect to the new ones. I know this question has been asked and answered before, but those answers aren't working for me.

    For example, going to http://gpaciga.clawz.com/wordpress/2005/10/vinge-singularity.html should take you to
    http://gpaciga.clawz.com/wordpress/2005/10/vinge-singularity/

    To accomplish this I have in my htaccess file the line

    RewriteRule ^([0-9]{4})/([0-9]{1,2})/([^/]+).html$ $1/$2/$3/ [QSA,R]

    but this doesn't work. I just get a 404 error.

    I know that mod_rewrite works because I've been using it to redirect any requests for a .html page to its .php version. One problem I came accross when doing that though was I noticed subdirectories didn't inherit the htaccess file of their parent directories in the absense of their own htaccess file, as I thought they were supposed to. At least that means the html-to-php rule won't affect the wordpress directory, but maybe it's causing problems now in a different way.

    Any help resolving this would be appreciated.

  2. Poco
    Member
    Posted 7 years ago #

    I'm no mod_rewrite expert, but I believe that is the correct rule if you had your blog in the root directory.

    However, since you have your wordpress blog in a directory called "wordpress" the rule probably needs to be updated with that in mind.

    Also, I'm assuming that you didn't actually put your blogger blog into a directory called "wordpress" so how would the rewrite rule help? Or are you just testing it until you move it to a different directory?

  3. gpaciga
    Member
    Posted 7 years ago #

    I'm just testing it now in the wordpress directory until I move it.

    I did try to take into account the fact that I have it installed in a subdirectory in a few ways without any effect. I have

    RewriteBase /wordpress/

    I also tried adding the subdirectory explicitly in the regular expression, as well as starting it with ^(.*)/. Maybe I'm just not using them correctly, but it's not working.

    At least I know that even though the rewrite goes to $1/$2/$3 without /wordpress/ explicitly, it's still within the /wordpress/ directory since I get the wordpress 404 error and not the one for my site.

  4. Poco
    Member
    Posted 7 years ago #

    I'm not sure that the wordpress 404 error is enough to suggest that it is almost working correctly. I would expect that even if you didn't have a mod_rewrite rule since you are asking the server for a non-existent file under the wordpress directory.

    I don't know much about mod_rewrite, but I would expect it to look something like this.

    RewriteRule ^wordpress/([0-9]{4})/([0-9]{1,2})/([^/]+).html$ wordpress/$1/$2/$3/ [QSA,R]

    You said that you tried "^(.*)/". Did you add a $4 to the second part of the expression?

    RewriteRule ^(.*)/([0-9]{4})/([0-9]{1,2})/([^/]+).html$ $1/$2/$3/$4/ [QSA,R]

  5. gpaciga
    Member
    Posted 7 years ago #

    Well, getting the wordpress 404 at least means that it's not rewriting to /2005/10/something... although you're right that I'd still get the error if it wasn't rewriting at all.

    Yes, I did add the $4 when using (.*), and I also tried writing out "wordpress" at the beginning as you suggested. It still does not work.

  6. Poco
    Member
    Posted 7 years ago #

    Well, then I'm all out of ideas. Mostly...

    Do you have any other RewriteRules? Maybe there is a conflict? You should post all your mod_rewrite rules to see if anyone can help.

    Also, does mod_rewrite work recusively? That is, if a parent directory has mod_rewrite rules in a .htaccess could they conflict or override the rules in a child directory? Hopefully someone can answer that.

  7. gpaciga
    Member
    Posted 7 years ago #

    My full htaccess file is:


    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^/wordpress/([0-9]{4})/([0-9]{1,2})/([^/]+).html$ /wordpress/$1/$2/$3/ [QSA,R]
    RewriteBase /wordpress/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /wordpress/index.php [L]
    </IfModule>

    # END WordPress

    Everything except line 4 was put there by WordPress. I have tried my rule (line 4) with and without the /wordpress/ explicitly, and before the #BEGIN line (with its own RewriteEngine On). As I understand it RewriteRule . /wordpress/index.php is a catch-all, so I should at least have my rule before that.

    I have in my root directory an htaccess with the rule

    RewriteRule ^([^/.]+).html$ $1.php [L]

    It has been my experience, however, that this does not affect any subdirectories (possibly because of the [^/] but I'm not sure), so it shouldn't be conflicting with the WordPress rules. However, just to be safe, I did alter my rule to .php in case my requests for the .html were getting written to .php before going through the WordPress rules. This did not seem to be the case.

    Can anyone see where I'm going wrong?

  8. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    Hah. This one took a while to figure out.

    As you correctly discovered, the RewriteRule . /wordpress/index.php is a catch-all. What you missed (and so did I) is that it is, in fact, catching all. Everything that makes it down that far, anyway.

    In your new Rule, change the [QSA,R] to [QSA,R,L]. The L means Last and it stops any further rewrite processing.

    Your rule is working. It's just getting overridden by the actual last rule. :)

    Use this, in other words:
    RewriteRule ^([0-9]{4})/([0-9]{1,2})/([^/]+).html$ $1/$2/$3/ [QSA,R,L]

    Might also want to put it after the RewriteBase directive. Keeps things a bit more consistent.

  9. gpaciga
    Member
    Posted 7 years ago #

    Fantastic! You're right, that's exactly what was happening. Even though it occured to me that my .html to .php rewrite rule might get applied first, I didn't think that subsequent rules could also get applied... seems obvious in retrospect. Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic