How do you do multiple redirects in a .htaccess file?

Can someone please give me the full code for a multiple redirect in an .htaccess file? This is what I want to do:

  1. Redirect the main page to another site (sitepoint.com to disney.com)
  2. Redirect sitepoint.com/design to disney.com/design
  3. Redirect sitepoint.com/resources to disney.com/resources
  4. Redirect sitepoint.com/articles to disney.com/articles

All other pages would redirect as the main page. I just need a few pages to be exempt. It would be nice to also know how to do a fourth or even more that would be exempt, too. Please give me the entire code as I’m not sure how to do this. Thank you.

This question is best suited for Server Configuration so I moved it there. Nothing in your question relates to HTML&CSS.

1 Like

Welcome to the forums, @premack.

Redirect 301 /index.html /newdomain.com/index.html
Redirect 301 /design /newdomain.com/design
Redirect 301 /resources /newdomain.com/resources
Redirect 301 /articles /newdomain.com/articles

That should redirect those pages/directories you’ve specified, but I don’t know how you would redirect all others to newdomain.com/index.html, except by specifying them individually. Hopefully somebody else can offer a better solution.

This might be of interest: https://perishablepress.com/stupid-htaccess-tricks/#redirects

May I suggest using 302 redirection instead of 301 because 302 is only a temporary redirect. The global DNS Routers will not permanently store the redirection and check your site to ensure the temporary redirection is still valid.

After a couple of days and you are absolutely sure all redirections are working satisfactorily then change the 302 redirection to 301 to make the redirection permanent.

The reason is that once the 301 has been registered it is tremendously difficult and virtually impossible to revoke.

Unfortunately I have the T-Shirt :frowning:

Edit:

Thank you! I will test this code out and let you know if it works.

A 302? Oh dear, now I’m torn as to which to do… Thank you for the suggestion. I’m worried now that if I try the 301 code I will permanently ruin my domain?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.