: 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
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?
More posts by @LarsenBagley505
2 Comments
Sorted by latest first Latest Oldest Best
Apache's mod_alias supports syntax for it without needing rewrite rules:
RedirectMatch permanent (.*).gif$ www.anotherserver.com.jpg
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.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.