Reputation: 33
On a site that was once migrated from .asp to .php, I used the following in the .htaccess file to ensure users following old links would end up on the right page:
RewriteEngine On
RedirectMatch 301 (.*)\.asp$ http://www.website.org/$1.php
I just moved the site to a new server, where requests for .asp pages now end up with an extra slash in the address, immediately before the page name:
http://www.website.org//page.php
(How) can the above .htaccess code be tweaked to eliminate that extra slash?
Upvotes: 3
Views: 492
Reputation: 71
Try this way:
RewriteEngine On
RewriteRule ^(.*)\.asp$ http://www.website.org/$1.php [NC,R=301]
Upvotes: 0
Reputation: 785481
You're making an assumption that RewriteEngine On
is needed for RedirectMatch
but it is not. RedirectMatch
is directive of mod_alias
and other one is from mod_rewrite
.
You can fix your code by using either of these two code:
Option 1:
RewriteEngine On
RewriteRule ^(.+?)\.asp$ http://www.website.org/$1.php [L,NC,R=301]
Option 2:
RedirectMatch 301 ^/(.+?)\.asp$ http://www.website.org/$1.php
You also need to make sure to test it after clearing your browser cache or in a new browser to avoid old browser cache.
Upvotes: 1
Reputation: 98961
Have you tried this?
RewriteEngine On
RedirectMatch 301 ^.*/(.*)\.asp$ http://www.website.org/$1.php
Upvotes: 0