How to point the subdomain to Main domain sub folder - php

I have the site domain.com and creates the need subdomain.domain.com that points to the directory domain.com/public_html/subdomain
How do I do that?
The subdomain folder must be within the public_html folder domain.com
The vestaCP possesses the possilidade to choose the root folder of the subdomain?
Sorry for my bad English.
Simply put:
I need it:
sub.domain.com> /home/user/web/domain.com/public_html/subdomain
No:
sub.domain.com> /home/user/web/sub.domain.com/public_html

I always solve it by one of this 2 ways (each of them has advantages and disadvantages):
I redirect the subdomain by .htaccess file to the folder inder the main domain. So i just add Redirect 301 / http://example.com/subfolder to the .htaccess file of subdomain. It's classic unmasked redirection.
I make a PHP file index.php in /home/user/web/sub.domain.com/public_html folder with this content: <?php print file_get_contents("https://example.com/subdomain/"); ?> and in folder /home/user/web/example.com/public_html/subdomain is website. Phe PHP file displays the whole content of website on main domain folder.
None of them is the real solution, it's just a how to hack it, but I hope it will be useful

Related

How upload files in root domain while in subdomain

I've a domain and a subdomain with this structure:
Domain: mydomain.com
Subdomain: m.mydomain.com (which "mydomain.com/mobile/" is the folder)
While I'm on mydomain.com, I upload images to the folder "images", this is the structure:
mydomain.com/images/image.jpg
And I've no problems with it, because the folder /images/ is in the domain.
Now, when I'm in m.mydomain.com, how can I upload images to the domain folder (mydomain.com/images) and not to the subdomain folder (m.mydomain.com/images)?
Thank you guys
PS. I'm using Routing with both domains, with the index.php as "router"
Since m.domain.com is in domain.com you can use m.domain.com/images for both.
Use the same directory for both domains and use .htaccess to route the mobile to index.m.php or something like that in the same directory.
More complicated. You can serve files through a url page built in php. Basically just a page that takes the file name searches for it in the server directory outside the site and dumps the content with appropriate headers.
Similar to 2 you can route both mobile and normal to the same directory. Detect in index.php if the subdomain is specified and load the site files from your mobile folder. This is my preferred method.

Folder structure website php

Lets say I have the website url www.example.com. My index.php page is in the root directory. I then want to have a page at www.example.com/someDir as well as a page at www.example.com/someDir/anotherDir. I thought that I would make the directory someDir in the root directory and make the directory anotherDir within the directory someDir, then place an index.php page in both those new directories which would be the visible page at those URLs.
Is this the proper way?
Yes.
Note that your web server (apache or whatever) should redirect www.example.com/someDir to www.example.com/someDir/ (with a trailing slash) which will make the relative links work correctly with respect to the index.php files.

Displaying content outside the website's root directory when a user visits the website

A website that I work on has many directories that are each websites of their own. The idea is that when someone visits the website like this: http://www.foo.com/bar that the index.html / index.php for each bar (and whatever other files are needed to display it) are shown to a client.
The main website (foo.com) has its root directory in the /www/... path. The files for the main website are all at the website's root directory.
At the moment all of the bar directories are in the /docs/... path which is not normally accessible by visiting the website. However, there are symbolic links at the website's root directory for each bar that go to the appropriate /docs/... path.
Although this works, I would prefer not to have a symbolic link for each bar in the website's root directory.
What I would prefer to do is have a PHP script (or another kind of script if necessary) that determines if some bar exists in the /docs/... path and if it does display that to a client without all the symbolic links.
Is this possible and if so is it possible to do without making the URL appear to be different to a visiting client?
Apache alias is the answer, its much like a symbolic link allowing Apache to access directories outside of the web root as if they were inside the webroot
Alias /foo /bar
Alias Directive

.htaccess Redirect images folder to another domain

ok so i have 2 domains
site1.com/images/ (all images)
and I need to redirect the imgages link site1.com/images/ to site2.com/images/ so that when
and when exp. site1.com/images/i.jpg is called it will look at site2.com/images/1.jpg and will find it.
.this is basic duplicate of the site and i don't want to move images back and forward.
Put in your .htaccess on site1.com
Redirect permanent /images http://sites2.com/images
If the websites are on the same server and running under the same user, you could use symbolic links between both websites.
E.g., create a symlink to /home/site2/public_html/images in /home/site1/public_html/images. Another option is using the Apache's Alias directive:
Alias /images /home/site2/public_html/images
Put this in the vhost config of site1.
Using redirection on Apache:
RedirectPermanent /images http://site2.example.com/images
The best way would probably fixing the HTML code pointing to one domain. If you cannot decide which domain should get the static content, create a subdomain (or even a different domain) to store the files.

Directory of "index.html" on site

I wonder if the index.html MUST be in the "www" folder on the server after uploading the site?
This because I have actually made everything in a folder called "SV", so my site is located in : "www/SV/index.html"
My Q is, on the server, could I just create a folder named "SV" under "www" and expect index.html to be automatically displayed ones the users type in the web-adress to my site?
Thanks
well, if they went to www.yoursite.com/SV then it would display. If you don't want that, you have a few options:
Put an "index.php" file in the "www" directory and have it redirect to the one in the /SV folder.
Change the apache configuration to tell it the site is located in the /SV directory.
Use mod_rewrite rules in your .htaccess file to rewrite URLs so they go to the /SV directory.
But my first question would be why don't you just put it in the "www" directory?
You should configure your web server so that the document root points to the path where your index.html is located
In general, any directory may be assigned as the web-root.
But in your particular case of shared web-hosting I doubt you can have access tho the server config to do it.
Though there can be some tricks done, using PHP or mod_rewrite. With more certain question describing background, you can get more certain answer.

Categories