How to redirect Page.aspx?=

I’ve recreated a new site using WordPress on an Apache server that used to be a .NET site, the old page URLS look like this:

Page.aspx?p=70 

I need to 301 redirect all of the pages to their new pretty URLS using .htaccess

Read More

When I use

Redirect 301 /Page.aspx?p=70 http://example.com/foobar

It doesn’t work, and WordPress sends it to

/?attachment_id=70

My .HTACCESS looks like this

Redirect 301 /Page.aspx?p=70 http://example.com/foobar

# 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>

# END WordPress   

Related posts

Leave a Reply

1 comment

  1. Have it this way:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{QUERY_STRING} ^p=70$ [NC]
    RewriteRule ^Page.aspx$ /foobar? [L,NC,R=301]
    
    RewriteRule ^index.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress
    

    And remember that %{QUERY_STRING} is not matched using Redirect directive.