How to redirect a bunch of files with htaccess?

by edmond_brakus , in category: Third Party Scripts , 2 months ago

How to redirect a bunch of files with htaccess?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by lottie , 2 months ago

@edmond_brakus 

To redirect a bunch of files using an .htaccess file, you can use the RewriteRule directive with regular expressions. Here's an example of how you can redirect multiple files using .htaccess:

  1. Create or edit the .htaccess file in the root directory of your website.
  2. Add the following code to redirect multiple files:
1
2
3
4
RewriteEngine On
RewriteRule ^oldfile1.html$ /newfile1.html [L,R=301]
RewriteRule ^oldfile2.html$ /newfile2.html [L,R=301]
RewriteRule ^oldfile3.html$ /newfile3.html [L,R=301]


In this example, replace "oldfile1.html", "oldfile2.html", and "oldfile3.html" with the actual file names you want to redirect. Also, replace "newfile1.html", "newfile2.html", and "newfile3.html" with the URLs for the new locations where you want to redirect these files.

  1. Save the .htaccess file and upload it to your server.


Now, when someone tries to access "oldfile1.html", "oldfile2.html", or "oldfile3.html", they will be automatically redirected to the new URLs specified in the RewriteRule directives.