WordPress.org

Forums

[resolved] Mod_rewrite or redirect? (5 posts)

  1. phobic
    Member
    Posted 2 years ago #

    Hi there

    I have a fairly standard WP permalink setup with this in my .htaccess file:

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

    However, I need to change the name of a page, and I'd like to setup a rewrite/redirect from the old page to the new. In other words, this URL:

    http://example.com/old-page/?story=978

    should forward/rewrite to this:

    http://example.com/new-page/?story=978

    Eventually the rewrite won't be required, I just need to be sure that any links to the old page remain in place.

    Any suggestions greatly appreciated!

  2. Greg Stewart
    Moderator
    Posted 2 years ago #

    Using a redirect directive in your .htaccess file seems the easiest method if it's only a single page, or a couple of them:

    Redirect 301 /old-page/?story=978 /new-page/?story=978
  3. phobic
    Member
    Posted 2 years ago #

    thanks for the reply - I figured I could redirect, but I'm having trouble because those are dynamic URLs - there are many stories generated by a plugin. On a clean site I could probably figure this out with trial and error, but I'm having trouble coming up with a rewrite/redirect regex that plays nice with the existing wordpress permalink structure.

  4. Greg Stewart
    Moderator
    Posted 2 years ago #

    Are you looking to redirect *all* /old-page/ to /new-page/?

    If so, try this, it will keep the query string and force a 301 permanent redirect:

    RewriteRule ^old-page/(.*?) new-page/$1 [QSA,R=301]
  5. phobic
    Member
    Posted 2 years ago #

    That looks like it will do the trick - many thanks jgs!

Topic Closed

This topic has been closed to new replies.

About this Topic