How to redirect an entire directory to a different domain using .htaccess Apache Directives

StackOverflow https://stackoverflow.com/questions/23610089

  •  20-07-2023
  •  | 
  •  

Question

I have the following directive in a .htaccess file in a directory off the document root called "redirect":

# 2014-05-12 redirects all/any pages in this directory to https://new.domain.com/forms/test/
Redirect 301 / https://new.domain.com/forms/test/index.php

Yet when I logon to http://current.domain.com/redirect (the home of the .htaccess file) the result is a page not found and the URL shows:

https://new.domain.com/forms/test/index.phpredirect

Why/how is this happening?

Was it helpful?

Solution

You should use mod_rewrite instead of matching exact URI pattern as it support regex match.

RewriteEngine On
RewriteBase /redirect/

RewriteRule ^$ https://new.domain.com/forms/test/index.php [L,R=301]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top