WordPress.org

Ready to get started?Download WordPress

Forums

need a redirect rule to send old permalink stucture to new one (7 posts)

  1. sallam
    Member
    Posted 4 years ago #

    Greetings
    Years ago, I set my custom permalinks to:
    /%postname%.html
    And now that I know this was a bad choice, I tried to change it to: /%category%/%postname%
    But the problem is that the links in google now give 404 error pages.
    Is there a code I can add to my htaccess to redirect links from the old strucutre to the new one please?

    Currently, my htaccess has this:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    # END WordPress

    Many thanks.

  2. Put this before the WordPress bit:

    <IfModule mod_rewrite.c>
      # Always use www.
      RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
      RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
    
      # Change urlpath.html to urlpath
      RewriteEngine On
      RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
      RewriteRule ^(.*)\.html$ http://www.example.com/$1 [L,R=301]
    </IfModule>

    I've used this before and it works. You can probably get away with removing the www forcing, but I'm not sure and this way it'll always be consistent.

  3. sallam
    Member
    Posted 4 years ago #

    Thanks for the code.
    Is there a code that doesn't involve the www bit? I don't use them as my blog is in a subdomain.
    what about a code to redirect
    from: /%postname%.html
    to: /%post_id%/%postname%

  4. Then just this may work

    <IfModule mod_rewrite.c>
      # Change urlpath.html to urlpath
      RewriteEngine On
      RewriteCond %{HTTP_HOST} ^subdomain\.example\.com$ [NC]
      RewriteRule ^(.*)\.html$ http://subdomain.example.com/$1 [L,R=301]
    </IfModule>

    The forcing the www was to make sure it was consistent, but if you're on a subdomain, it shouldn't be needed anymore.

  5. sallam
    Member
    Posted 4 years ago #

    Thanks, but your code didn't work in my case.
    But thanks for trying to help.

  6. sallam
    Member
    Posted 4 years ago #

    any other help please?

  7. Hmm. Okay, what I gave would translate example.com/foobar.html to example.com/foobar

    For postID/foobar though ... I don't know how you can move those, since the ID isn't detectable from just the URL.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.