Mobile app version of vmapp.org
Login or Join
LarsenBagley505

: 301 redirect all pages with a specific extension I have a website that is not on ASP anymore, it's a Drupal 7 website now. I need to use an .htaccess file to redirect with code 301 all

@LarsenBagley505

Posted in: #301Redirect #Apache #Drupal #Htaccess #Seo

I have a website that is not on ASP anymore, it's a Drupal 7 website now.

I need to use an .htaccess file to redirect with code 301 all pages with .asp extension to the 404 page or a specific URL.

(Background story: Drupal will catch non-existing pages such as domain.com/test and redirect to 404 page. But Drupal will not catch non-existing pages with ASP extension such as domain.com/test.asp and it will instead serve a generic Not Found Apache page.)

For example, if someone tries to access domain.com/test.asp, the user should be taken to domain.com/404

I have searched and searched but I can't find a solution to this particular problem. How can I code that in an .htaccess file?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @LarsenBagley505

2 Comments

Sorted by latest first Latest Oldest Best

 

@BetL925

Apache's mod_alias supports syntax for it without needing rewrite rules:

RedirectMatch permanent (.*).gif$ www.anotherserver.com.jpg

10% popularity Vote Up Vote Down


 

@Ravi8258870

RewriteEngine On
RewriteRule ^.+.asp$ domain.com/404 [R=404,L]


Aughta do the trick :) It's pretty self-explanatory, it just rewrites every page that ends in .asp to your 404 page.

You should use 404 instead of 301 since you want to tell Google the page doesn't exist anymore. You can use 301, but then you'd have to redirect to a useful new page.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme