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?
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.
Have you tried this?
RewriteEngine On
RedirectMatch 301 ^.*/(.*)\.asp$ http://www.website.org/$1.php
Try this way:
RewriteEngine On
RewriteRule ^(.*)\.asp$ http://www.website.org/$1.php [NC,R=301]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.