Support » Fixing WordPress » 301 Redirect Old Site Dynamic URLs To WordPress Permalinks

  • Hi,

    Summary: Is there a way to use permalinks in .htaccess redirects instead of parameter-based URLs?


    There is a post from a few weeks ago (see which discussed redirecting from site A (old site) to site B (new WordPress powered site) using .htaccess 301 redirects. The solution was to redirect to the parameter-based URLs instead of their permalink URLs equivalents. While this solution works for me, I would like to know how to use the permalink structure, if only out of curiosity (not to mention the inconvenience of finding the ID # of every WordPress resource to redirect to).

    In the aforementioned previous post a mooted solution was, e.g., ‘Redirect 301 /index.php?page=2‘. I’ve tried and failed using this method. Apache seems to completely ignore that line. Here is the .htaccess file used to test:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    Redirect 301 /index.php?page=mypage
    RewriteBase /blog/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /blog/index.php [L]

    In this case, the Redirect command is ignored and no redirect takes place.

    And so, is there a way to use permalinks in redirects?


Viewing 3 replies - 1 through 3 (of 3 total)
  • I am having the same issue and would be fascinated in the answer.


    The trick with those dynamic URLs (the ones with &s and all that) is that htaccess code has to be written a little bit differently.

    In your example, if you want to redirect index.php?page=mypage to, you have to do it this way:

    RewriteCond %{QUERY_STRING} ^page=mypage$
    RewriteRule ^index\.php$ [R=301,L]

    Basically, take everything you see after the index.php? and put it in the first line (don’t forget that $). The new URL goes in the second (don’t forget the ?)

    Important: be sure to put all this code before the WordPress permalink rewrites, or else it won’t work.

    Good luck, hope that helps!




    Thank you for your solution. I recently returned to this issue and I’m now using something very similar to that which you’ve suggested.


Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘301 Redirect Old Site Dynamic URLs To WordPress Permalinks’ is closed to new replies.