• Resolved Sebastian

    (@sebstein)


    Hi folks,

    I’m currently migrating my blog to wordpress. Seems to work just fine, but I also want to migrate some of my old permalinks, because there are some links in the net pointing at them. Basically, it should be possible to do with mod_rewrite, but I can’t get it working.

    Example of old permalink:

    https://domain/blog/fixedstring/variablestring/2007/05/01/entry

    Same post with new permalink:

    https://domain/2007/05/01/entry

    So basically I have to remove “blog/fixedstring/variablestring/”. I would write the following rule:

    (^blog/fixedstring/.[a-z]*/)(.*) $2

    This works, if I use it outside of wordpress, but I don’t know how to integrate it with the standard wordpress .htaccess file. I thought it must work as follows:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule (^blog/fixedstring/.[a-z]*/)(.*) $2
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress

    Does anybody knows what is going wrong?

    Regards,

    Sebastian

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Try this instead:

    RewriteRule (^blog/fixedstring/.[a-z]*/)(.*) $2 [R=301,L]
    
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress

    You really never want to change WordPress’s rules directly. Consider the text between BEGIN and END to be inviolate unless you really, really know what you’re doing. ??

    Thread Starter Sebastian

    (@sebstein)

    I think the [R=301,L] at the end did the trick, because I already tried it with out it. So what does it actually do? Can I use several rules, for example to rewrite the old feed URL?

    Sebastian

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    R=301 causes it to send a redirect to the browser, changing their URL. The reason for the 301 is to say that it’s a Permanent Redirect. This allows search engines to recognize that your URL has changed and update themselves accordingly. Without the =301 it would send a 302 (by default) and that’s a Temporary Redirect.

    The L makes it the Last rule in the processing chain. Once it hits that, it stops processing. For a redirect, you almost always want an L in there to stop the server processing and immediately force the user to the new URL.

    You may want to read the documentation for mod_rewrite.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘mod_rewrite: remove string’ is closed to new replies.