[Feature request] Allow subdomain redirects in VirtualHosts

Neograph734

Verified User
Joined
Sep 17, 2014
Messages
18
I've stumbled upon this very old feature request [REQ] Subdomain Redirect and although it works, I don't feel this is the pretty way to solve this issue.

Above issue suggests to create a subdomain (
Code:
sub.example.com
) using the UI, then add an .htaccess file in the subdomain folder
Code:
example.com/public_html/sub
so it can redirect to something like
Code:
www.example.com/some/path
using a redirect in .htaccess.

The downside of this method is that it is:

1. Difficult to explain to co-workers, because it is not directly obvious how the construction works.
2. Difficult to maintain, because you need to dig into the files to see what subdomain goes where.
3. Limiting, I cannot use
Code:
example.com/sub
as a pretty URL because that resolves to a real folder.

Since DirectAdmin can write the Virtual hosts already, I suppose it should be relatively easy to create these kinds of redirects at the VirtualHosts level, with some overview in the UI of all redirects and options to create new ones. This would make these kinds of operations easier to maintain and allow more flexible sub- / pretty-url combinations, so
Code:
sub.example.com
can redirect to pretty url
Code:
example.com/sub
.
 
Just a question because I don't see the benefit of this at the moment.
Why create a subdomain if you want to make use of example.com/sub anyway?
Why not just creating a subdirectory /sub under public_html, then you can also visit it via example.com/sub and there is no need to be redirecting sub.example.com to example.com /sub.
 
Why create a subdomain if you want to make use of example.com/sub anyway?
Why not just creating a subdirectory /sub under public_html, then you can also visit it via example.com/sub and there is no need to be redirecting sub.example.com to example.com /sub.

A subdomain would allow one to dive much deeper into a pretty url. For instance if we are to host an event we'd like to use coolevent.example.com (easy to remember on posters, flyers etc) and redirect it to a pretty url on the main site. For example something like example.com/events/local/april/12/coolevent. This is not a real path on the filesystem, but the main index.php file is fetching the correct data from the database for this page.
This is the main reason for my request.

Point 3 of my first post is something I ran into with one specific situation where the pretty url and the subdomain did match (this never happened before) and I was using the method explained in [REQ] Subdomain Redirect. This led to the situation where my pretty url example.com/sub was no longer handled by the main site, but was opening the folder on the filesystem. It was an example to demonstrate that the solution in the other thread is not ideal.
 
I recently ran into this same problem. It would be very nice to see a solution for this problem!
 
Back
Top