.htaccess 301 redirect add extra slash

On a site that was once migrated from .asp to .php, I used the following in the .htaccess file to get users following the old links to 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 with an extra forward slash in the URL, just before the page name:

http://www.website.org//page.php

      

(How) can the previous .htaccess code be modified to exclude this extra slash?

+3


source to share


3 answers


You make an assumption of what is RewriteEngine On

needed for RedirectMatch

, but it is not. RedirectMatch

is a directive mod_alias

and the other is from mod_rewrite

.

You can fix your code using either of these two :

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 check it after clearing the browser cache or in a new browser to avoid using the old browser cache.

+1


source


Have you tried this?



RewriteEngine On
RedirectMatch 301 ^.*/(.*)\.asp$ http://www.website.org/$1.php

      

0


source


Try this way:

RewriteEngine On
RewriteRule  ^(.*)\.asp$ http://www.website.org/$1.php [NC,R=301]

      

0


source







All Articles