Site Redirection

timzelf

New member
Joined
Jun 7, 2024
Messages
1
I want to redirect visitors to a certain domain elsewhere, and I want to do the same for several subfolders. DirectAdmin's "Site Redirection" feature generates a .htaccess file looking like this:

Redirect 301 /subfolder1/ https://newdomain.com/subfolder1/
Redirect 301 /subfolder2/ https://newdomain.com/subfolder2/
Redirect 301 /subfolder3/ https://newdomain.com/subfolder3/
Redirect 301 /subfolder4/ https://newdomain.com/subfolder4/
Redirect 301 /subfolder5/ https://newdomain.com/subfolder5/
Redirect 301 / https://newdomain.com/

Which seems fine. However, the last line - redirecting / - takes precedence over all other lines. So redirecting the subfolders *only* seems to work properly when I leave that last line out. I can think of a workaround to fix this outside of the "Site Redirection" feature, but why should that be necessary? When you're taking the trouble to redirect a number of individual pages to individual pages on a new domain, isn't it logical that you'd also want to redirect visitors to the old domain's homepage to the new domain's homepage? I don't entirely understand why I can't do both from the "Site Redirection" feature.
 
Seems DA is working backwards on this.

Try setting the last line as first line. Good chance that will do what you want.

If yes, to prevent DA to make the wrong change again, disable the Site Redirection in DA itself and then create a .htaccess file yourself with that content.
 
Hello,

Yes, the order should matter. According to the official documentation:

- https://httpd.apache.org/docs/2.4/en/mod/mod_alias.html

They write: "For this reason, when two or more of these directives apply to the same sub-path, you must list the most specific path first in order for all the directives to have an effect."

In the fact Apache 2.4 behaves the way it is mentioned. I tested it on my end, and can confirm the directives work as designed.

If it does not work on your side, you might test with CURL to avoid caching in a browser. And/or provide a real domain name, so that we could test it from our side.

Which seems fine. However, the last line - redirecting / - takes precedence over all other lines.
 
Back
Top