WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Permanent redirect 301 with .htaccess (8 posts)

  1. bloggenbent
    Member
    Posted 7 years ago #

    I'm running wordpress under xoops cms in a subdomain at (http://bloggenbent.dagenspolitik.se). This is a wordpress problem and not a xoops problem, so I ask my question here.

    Right now I'm in the process of moving the blog out of that domain to a new one, but I'm having some issues with the .htaccess rewrite rules.

    This is what I'm writing

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /modules/wordpress/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /modules/wordpress/index.php [L]
    RewriteRule ^(.*)$ http://www.bloggenbent.se/$1 [R=301,L]
    </IfModule>

    Basically what I want to do is have a rule that takes a link like:

    http://bloggenbent.dagenspolitik.se/modules/wordpress/2007/08/24/strningar-kan-frekomma/

    and turn it into:

    http://bloggenbent.se/modules/wordpress/2007/08/24/storningar-kan-forekomma/

    As you can see, only the domain changes. Everything else is exactly the same.

    I tried to read the draft article here on wordpress.org about this, but this section hadn't been done yet.

    Does anyone know how to repoint the site as mentioned above? Thank you.

  2. mrmist
    Forum Janitor
    Posted 7 years ago #

    Firtsly, move your rule outside of the WordPress rules section, because otherwise your rule will be removed.

    Then I think you would need to put your rewrite rule at the top and make it an L rule, so that it gets processed first and redirects stuff to the domain, where it can then be looked at by the WordPress rules.

    Just watch out for infinite redirection loops if it doesn't work.

  3. bloggenbent
    Member
    Posted 7 years ago #

    Thank you for your reply. Just to clarify, what do you mean by this: WordPress rules section. Sorry if I'm a bit thick. I've tried just about any permutation of the rewrite line - alone in the htaccess file and with everything else.

    Redirection often works, but it just redirects to my front page:

    http://www.bloggenbent.se/modules/wordpress

    I should mention that the wordpress that's stuffed into Xoops is 2.2.1.

    Extra: I should also mention that I haven't dared putting any htaccess-file in directories above /modules/wordpress since I have another site running on this domain that may be affected.

  4. mrmist
    Forum Janitor
    Posted 7 years ago #

    What I meant was that - in 2.2.2 at least - WordPress sticks its alterations to the .htaccess file in a commented block like this -

    # BEGIN WordPress
    .
    .
    .
    .
    # END WordPress

    And if you put any of your own alterations in there manually they'll vanish whenever WP saves its changes to it. (Which it seems to do on various occasions dispite not really needing to.)

  5. bloggenbent
    Member
    Posted 7 years ago #

    Okay, thank you for your clarification. No, my WordPress doesn't do that.

    First of all, any file or directory in the /modules-folder is protected so WordPress doesn't have write access to most things - except the things it clearly needs. .htaccess files is a set of files it can't write to. I want it this way because I'm not a 100% sure about the marriage between WordPress and Xoops. Better be safe.

    Second, the above quoted code is the 'ordinary' .htaccess you get when you update your permalink structures in options. I've just tried lots of variants like:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^(.*)$ http://www.bloggenbent.se/$1 [R=301,L]
    </IfModule>

    ... and so on all the way up to what I quoted above. That should work, according to what I read on the net. But it doesn't. Or I'm doing something glaringly stupid.

    This is the first time I'm tinkering with .htaccess at this depth, as you well can see.

  6. Bodhipaksa
    Member
    Posted 7 years ago #

    My only experience is with having rules to redirect each individual page. So I have a long list of rules like

    RedirectPermanent /modules/wordpress/2007/08/24/strningar-kan-frekomma/ http://bloggenbent.se/modules/wordpress/2007/08/24/storningar-kan-forekomma/

    (all on one line, naturally).

    I don't know how large your site is, but I created an htaccess file for a 600 page site (moved from static html to WordPress) in about 30 minutes. I used an online "create a sitemap" tool to list all the pages in the site and then copied them to an Excel spreadsheet where I did some searching and replacing before exporting to a text file.

    Of course there's probably a niftier way of doing this using a single htaccess rule -- I'm strictly a dabbler. But, hey, it worked!

  7. mrmist
    Forum Janitor
    Posted 7 years ago #

    Here's one variant of redirecting (all non-domain) traffic to your actual domain address -

    RewriteCond %{HTTP_HOST} !^www.yourdomain.com [NC]
    RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]

    I'm not convinced that that would work, but worth a try.

    Also, you may need to do one or both of -

    Put a RewriteBase directive in to indicate what subdirectory your .htaccess is relative to.

    Put the conditions for redirecting the sub-domain into your root folder .htaccess rather than in a sub-directory.

  8. bloggenbent
    Member
    Posted 7 years ago #

    It works now. Thanks you who replied. This is the code that worked. :)

    RewriteEngine On
    RewriteBase /
    
    RewriteRule ^(.*)$ http://www.bloggenbent.se/modules/wordpress/$1 [R=301,L]

Topic Closed

This topic has been closed to new replies.

About this Topic