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.
Related
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
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
I have a php websites hosted on a server. I use CPanel to manage it. public_html has lets say following directory structure
public_html
- dir1
- dir2
- dir3
- ....other files.....
- website2home
Now I am trying to make website2home as the base directory of my website, but files inside website2home use some files from public_html folder and some files from within itself.
THE PROBLEM
When I assign a domain name to website2home, It does not reads the files from public_html folder (in fact, public_html folder is not visible) and shows some php warnings and some 404 not found errors. But lets say the domain name for original website is www.aaa.com, then if I access website2home by using www.aaa.com/website2home all works fine.
So My Question...
Is there any way to set the base directory, so that my website2home fetches all files and correct files without replacing hundreds of filepaths in php code?
Please answer considering that I don't want to modify source files of website.
I believe you are looking for some kind of .htaccess configuration. For instance, you may set your website2home folder as base folder for your www.aaa.com domain and then redirect some file access to other folders using .htaccess, something like this..
RewriteEngine on
RewriteRule captcha.jpg ../captcha.jpg
RewriteRule \.pdf$ ../pdf_files/$1
Have a look to mod_rewrite documentation
Edit: If, for some reason, the ../ redirection doesn't work, you always can redirect all your files to a pseudo-index PHP page. For instance:
RewriteEngine on
RewriteRule captcha.jpg my_index.php?access=../captcha.jpg
RewriteRule \.pdf$ my_index.php?access=../pdf_files/$1
And then, in your index PHP page you can simply load your PHP files in other folder:
require "../pdf_files/$requested";
Right now I have a assortment of 9 files (javascript, image, stylesheet, php) in the root directory of my web server. I would like too put all of these files in a directory called home (for home page). So now at this point I can view my home page at http://example.com/home.
I would like it so that when you visit http://example.com/ it points to the files in the home directory.
I am using php so my first attempt was to create a index.php in the root and include the index from home. This breaks relative URLS within styles, javascript, and includes. To combat this I prepended my includes with $_SERVER['DOCUMENT_ROOT'].'/home/. More problems arise when I try to redirect http://example.com/home to http://example.com/.
Is their any better way of doing this, possibly with .htaccess?
Yes, if your server supports mod_rewrite, you could probably add a RewriteRule:
RewriteRule /(.*) /home/$1 [R,L]
In your Apache httpd.conf change the DocumentRoot to your "home" folder.
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.