Hi, I need to create subdomains to point files and subdirectories: 1. subdomain.example.com pointing to example.com/subdomain < /public_html/subdomain/ >. 2. file,example.com pointin to example.com/file.php < /public_html/file.php >. I would prefer to automate the process with an script instead of making it one by one but I would appreciate your help to make it in any of the two ways. Thank you
Ensure you have 'Create subdomains as web site' enabled under System > Main Config > Sites With the aforementioned setting enabled, this is exactly what happens when you add a 'Subdomain (Vhost)' (you specify the subdomain name, path to web folder, and other settings). If using apache, change the DirectoryIndex for this subdomain to be (or to include) 'file.php'. I'm not as familiar with nginx, but I believe you have to specify a config section which accomplishes that. You can use the remote api to script the creation of websites, subdomains, etc. Set up at least one manually in the ISPConfig interface first so you can reference what goes into each of the db tables (which correspond to the fields in the remote api).
I guess this solution uses a directory but I need a subdomain without it, only a file like this < /public_html/file.php > not < /public_html/subdomain/file.php > Instead, please let me know how to modify the files where ISPconfig defines subdomain.example.com pointing < /public_html/subdomain/ >, to replace "subdomain" for "file.php". I do not know how ISPConfig makes that configuration and what files are involved. Thank you for your help
just set the redirect path to /public_html that should set the subdomain to use exactly the same webroot as the main domain. then in the vhost configuration for this subdomain, set 'DirectoryIndex file.php' i assume this can be set in the apache directives section on the options tab for the website, but it's not a directive i've tried setting before, so can't confirm that.
I do not know what to enter in [Subdomain for website / Redirect Path ] to point </public_html>. I neither know how to make DirectoryIndex to open </public_html/file1.php> when <file1.example.com> is requested and </public_html/file2.php> when <file2.example.com> does. I also wonder what does "redirect type" means, I did not find it in the documentation <docs.ispconfig.org/creating-web-sites/subdomains/>
we're just using /public_html as that's what you used in your initial example. if the full path to your main domain's docroot is /var/www/clients/client1/web1/web then with a subdomain vhost, the parent website will be the main domain, the domain will be the same, hostname will be the subdomain. the web folder will be /web for a subdomain pointing to a subfolder on the main site, parent website and domain would be the main domain, host would be the subdomain, redirect path would be /web/<path>/<to>/<subfolder> this page has more info on the redirects https://superuser.com/questions/592236/adding-a-domain-alias-in-ispconfig/593553#593553 you would probably be better off buying the ispconfig manual for £5, the stuff your looking at on docs.ispconfig.org looks rather sparse compared to the manual.
I have the manual and now I understand the flags concept. Thank you very much. I have two doubts yet: 1. What to enter in [Subdomain for website / Redirect Path ] to point </public_html>. The examples are made for directories inside the host, this way the name of the subdomain is entered in the field, but What if there is no directory? Do you have to use a wild card, let it blank...? 2. How to make DirectoryIndex to open </public_html/file1.php> when <file1.example.com> is requested; </public_html/file2.php> when <file2.example.com> does, and the same with </public_html/file3.php> and <file3.example.com>. My experience with DirectoryIndex is seting <index.html>, <index.shtml>, etc. to open when their directory is requested, they are sorted as are listed in the file,. In this case <index.html> will open with <www.example.com> and <example.com> always. Let me know if there is an additional configuration in DirectoryIndex to get what I need.
1. there will be a directory. if your main domain is example.com and your subdomain is sub.example.com the docroot for example.com will be /var/www/clients/client##/web##/web/ if you wanted the subdomain to point to a subfolder of the main domain, eg www.example.com/subfolder1/subfolder2 the redirect path for the subdomain would be /web/subfolder1/subfolder2 if you want the subdomain to point to the same docroot as the main domain, the redirect path would just be /web for the same examples, as a vhost subdomain, parent website and domain would be example.com, host would be sub, and webfolder would be /web/subfolder1/subfolder2, or for the same docroot as the main domain, just /web 2. if you want the subdomain to point to a file you would set the redirect path to http://example.com/<filename> or http://example.com/<subfolder>/<filename> if the file was within a subfolder on the main domain. or you create a vhost subdomain as above, and in the apache directives section set the directive: DirectoryIndex <filename> it will only apply within that vhost / subdomain. if there's still more subfolders within the subdomain eg sub.example.com/subfolder1/subfolder2 where subfolder1 contains file1.php and subfolder2 contains index.php the set it as DirectoryIndex file1.php index.php for the file2.example.com vhost subdomain you would set it as DirectoryIndex file2.php and for file3.example.com vhost, DirectoryIndex file3.php example.com itself will continue to use the default DirectoryIndex settings
actually, just double checked that, for a subdomain the redirect path would just be /subfolder1/subfolder2 you can't set it to use the same docroot as the main domain. you'd have to do it as a vhost subdomain (you could add the whole subdomain as an alias and then redirect that, but that's probably more complication that you need, especially if domain limits are enabled)
If I understand well, there the ISPConfig screen named [Subdomain for website] can not make a subdomain to point a file because its field named [Redirect Path] can not point to the folder </public_html> (this can only point to </public_html/subdomain> for <subdoman.example.com>) In other words such screen only makes subdomains redirected to subfolders. If this is the case, I am back to my original answer What shall I need to do for creating a subdomain pointing to a file in a server with ISPConfig?
create a vhost subdomain, pointing to the relevant folder. which would be /public_html according to your initial examples. AND set the 'DirectoryIndex file.php' apache directive
DirectoryIndex, as explained in its documentation <www.htaccess-guide.com/directoryindex-uses/>, can not do what I need: <file1.example.com> opens </public_html/file1.php> <file2.example.com> opens </public_html/file2.php> <file3.example.com> opens </public_html/file3.php> <fileN.example.com> opens </public_html/fileN.php> Instead, unless you provide the code, it does: <file1.example.com> opens </public_html/file1.php> <file2.example.com> opens </public_html/file1.php> <filen.example.com> opens </public_html/file1.php> I thought this would be a simple task with ISPConfig, but per your valuable contributions it seems such can not create the subdomain, neither the redirect to make <file1.example.com> opens </public_html/file1.php>. There must be something we are not considering.
You probably need: 1) A website in ispconfig with auto subdomain set to * 2) An apache rewrite rule, e.g. in a .htaccess file or in the apache directives field which uses the subdomain as a variable: RewriteCond %{HTTP_HOST} ^(.+).domain.com RewriteRule .* http://www.domain.com/public_html/%1.php [L,P] The above is untested and might need some further tuning, it's just a suggestion which route you could go. I recommend the apache rewrite documentation for reading: https://httpd.apache.org/docs/2.4/mod/mod_rewrite.html and https://httpd.apache.org/docs/2.4/rewrite/remapping.html
I guess the * must be entered at [Subdomain for website / Redirect Path] field. Is it the .htaccess in the <domain.com> </public_html/> folder to override the instruction of the VHOST file made in the step 1)?
No, auto subdomain is a field in the website settings and there you select *. The .htaccess file is in the web folder and it is not there to override any settings from 1).
Till, here I am again. May you help me with the information to make the same with Nginx (+ISPConfig 3). I found making it in Apache is time consuming for me and for the server. It seems Nginx is better because all the adjustments are made in a single file, but: 1. I do not know how to create the subdomain in ISPConfig+Nginx Is it the same than in Apache? 2. Where is the server file with the domain blocks or there is a different approach to make what I need. Thank you
It is the same. This I do not know. I have only used Apache, I find Nginx too complicated and difficult.
I think you'll find your nginx configuration under Sites->Website->Web_Domain->Options->nginx_directives