Is there any way to split the root and the other paths in apache2?
Clash Royale CLAN TAG#URR8PPP
Is there any way to split the root and the other paths in apache2?
I am not sure what the correct terminology is, so I'm just going to give an example.
I want to host my website in my root, using git so i can easily pull new versions of my portfolio as I update it. And then I also just want to have miscellaneous sub-paths that I just have there either for fun, or just something else entirely.
So I want to structure to be
html
│
└──── actualroot
│
└──── otherstuff
and then I want the user to be able to access actual root by just going to the domain name www.example.com
and then access the folder otherstuff
by going to www.example.com/otherstuff
www.example.com
otherstuff
www.example.com/otherstuff
Is something like this possible? Maybe by redirecting if it doesn't find the path? Or should I just use a subdomain for all miscellaneous sites?
Alias
Thanks! I'll take a look at it.
– stepper
2 hours ago
1 Answer
1
Sure this is possible.
However, it depends on your overall configuration. For a lot of hosters, it is a common pattern, to use the first-level-folder as subdomain-name.
I.e. in your example, you would have:
http://actualroot.mydomain.tld and
http://otherstuff.mydomain.tld
(so, it's easy to call the folder of your primary website "www")
Beside that, you can always use some simple htaccess
-rules to rewrite any virtual-path to the actual physical path.
htaccess
For instance (simplified, not complete, but should give you an idea):
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^www.mydomain.tld/otherstuff/(.*)$ ./html/otherstuff/$1 [R=301,L]
RewriteRule ^www.mydomain.tld/(.*)$ ./html/actualroot/$1 [R=301,L]
The user would enter www.mydomain.tld
and see the content, as if he would have accessed http://mydomain.tld/actualroot/
(www.mydomain.tld/otherstuff/
would show the content of http://mydomain.tld/otherstuff/
)
www.mydomain.tld
http://mydomain.tld/actualroot/
www.mydomain.tld/otherstuff/
http://mydomain.tld/otherstuff/
Please note that the processing order (along with
[L]
is important!) - You can save a lot of work, if you process "longer" paths first, and let every shorter path be processed by the "next" rule (if the prior rule doesn't apply)– dognose
8 mins ago
[L]
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Look at the
Alias
directive in apache2. (Writing an actually useful answer will probably take me longer than it takes you to solve it by looking it up!)– James Aylett
2 hours ago