Search code examples
wordpressmod-rewritepermalinks

Redirect old permalinks (page_id=x) wordpress


I used to have my permalinks to standard format, something like http://example.com/?page_id=2. Now I have changed this, using ISAPI rewrite in a httpd.ini file in the wp root folder. This is working, but I need to have the old page_id=x style pages redirect to the current permalinks which is in a form of http://example.com/subject.

I have looked at RedirectPermanent keywords etc, but nothing seems to really work. I have a very limited amount of pages, so a list where I specify all the page_ids is not really a problem. Anyone know how I can do this?


Solution

  • Found it. Maybe not the nicest trick in the book, but here goes:

    RewriteRule /(.*)?page_id=3(.*) /company_profile [L,I,RP]
    

    My complete httpd.ini file is now:

    [ISAPI_Rewrite]
    RewriteEngine On
    
    RewriteBase /
    RewriteCond ${REQUEST_FILENAME} !-f
    RewriteCond ${REQUEST_FILENAME} !-d
    # For special Wordpress folders (e.g. theme, admin, etc.)
    
    RewriteRule /wp-(.*) /wp-$1 [L]
    RewriteRule /google(.*) /google$1 [L]
    
    #Rewrites for permanently moved pages (page_id=x):
    RewriteRule /(.*)?page_id=3(.*) /company_profile [L,I,RP]
    
    # For all Wordpress pages
    RewriteRule ^/$ /index.php [L]    
    RewriteRule /(.*) /index.php/$1 [L]
    

    Hope this helps someone!