Directory of "index.html" on site - php

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.

Related

Apache directory issue which redirects request to index.php

I have a joomla website.
In my public_html where Joomla is installed, I have a directory named "logs-list".
When I go to the address http://example.com/logs-list/file.txt, I expect the file to be shown, but instead APACHE redirects to index.php, it assumes as if this is a request for Joomla. This has confused me. What should I do?
UPDATE
how I can tell in .htaccess to stick to the physical directory for a certain URL?

how to use htacces to restrict access to all files in a folder and it's subfolders and redirect to main?

So I'm on a 15-day trial of my (already paid) webhosting and they seem very good, at least they did until I got my FTP.
I have a php script that needs a folder outside of the root directory
Example:
website root:
/users/websites/public_html/ <- folder which users / browsers have access to
The script needs a folder here:
/users/websites/ <- above the root
for example /users/websites/sensetive_data/ <- browsers cannot acces this
but that's impossible on my web-host "because it's a shared hosting" <- their answer. And they can't change the root path.
So I cannot create any directories or files above /users/websites/public_html/
So, well, to no cancel my trial immediately, maybe I will try to do it in another way, I want to use htacces to restrict acces to a directory, and all the files in it and it's subdirectories,
So I can move the 'sensetive_data' folder to /users/websites/public_html/sensetive_data
I want it to redirect to the main page (so when accessing /users/websites/public_html/sensetive_data/* [http://example.com/sensetive_data/*] it will go to /users/websites/public_html/ [http://example.com/],
so even if the user knows the exact url, he/she will be redirected. How can I accomplish that?
If you want to do a redirect for a folder, say /users/websites/sensitive_data/
create a file in that folder called .htaccess and add the following (and specify the url to redirect to)
Options -Indexes
ErrorDocument 403 http://mysite.net/
In /users/websites/sensetive_data/.htaccess write:
Deny From All
For your whatever PHP script you need to change it yourself.

Server File Configuration: Using .htaccess to redirect to a script but pass CGI arguments aswell

I have an idea that will allow a Web Forums Content/Threads to be better indexed by search engines but avoid taking up too much unnecessary space on the web server.
My idea is not unique(I think StackOverflow uses it) but I am having difficulty working out how I am going to achieve redirecting through .htaccess commands or main server configuration files.
For a web forum website; when a new thread is created:
I store the thread HTML in an SQL database(rather than creating a HTML file which I think will take up more server space - is that correct?).
I create a directory on the server where the directory's name is the threads name(this will allow for easier indexing from google & other search engines wont it? Because the url is more descriptive?). So www.myForum.com/posts/unique_thread_name/. I think this is how StackOverflow does this, if you look at the url of my question its a directory.
The new directory(thread directory) will be empty except for a .htaccess file which will redirect to a script www.myForum.com/cgi-bin/loadWebpage.py. This script will grab the thread's HTML from the database when accessed & display that thread.
So when someone accesses www.myForum.com/posts/unique_thread_name/, the .htaccess file will redirect to www.myForum.com/cgi-bin/loadWebpage.py?thread=unique_thread_name. Notice the arguments, is it possible for a .htaccess file to redirect to a script but pass arguments aswell?
My Questions:
The apache website says you should never use .htaccess files "In general, you should never use .htaccess files unless you don't have access to the main server configuration file.". If I am using a webhost like GoDaddy do I have access to this file or is this server config file only for VPS?
Is it better to do this with the Server Config file instead?
Is there a way easier way of doing this? The whole idea is to store Forum Threads that take up as little space as possible but are still easy for search engines to index(thus the unique directories created).
Do I NOT need to create a .htaccess file in each post directory? Can I just write in my main .htaccess file that any request to a file/folder in posts should redirect to www.myForum.com/cgi-bin/loadWebpage.py?thread=the directory they accessed?
Maybe the code would look something like this?
Redirect /posts/* www.myForum.com/cgi-bin/loadWebpage.py?thread="HOW DO I SPECIFY THE FOLDER?"
If I am using a webhost like GoDaddy do I have access to this file or is this server config file only for VPS?
Godaddy shared hosting only allows .htaccess use.
Is it better to do this with the Server Config file instead?
Its better performing if you have access to Server Config, but shared hosting like Godaddy does not allow it.
Do I NOT need to create a .htaccess file in each post directory? Can I just write in my main .htaccess file that any request to a file/folder in posts should redirect to www.myForum.com/cgi-bin/loadWebpage.py?thread=the directory they accessed?
You can do it with a single .htaccess in the root dir of your site with contents as below
RewriteEngine on
RewriteBase /
RewriteRule ^posts/(.+)/$ /cgi-bin/loadWebpage.py?thread=$1 [NC,L]

How these index.html, index.php, .htacess files works ? Whats the purpose of these files?

How all these index.html, index.php, .htacess files works ? whats the purpose of these files?
This is a really broad question so I suggest you look it up. But here is start
index.html -- The default page that is going to be returned when someone visits your website
index.php -- same as above if .html file is not there
.htaccess -- loads custom mods or you can rewrite urls. This by it self is a whole book. So start here http://httpd.apache.org/docs/current/howto/htaccess.html
The index.* files are default files served if the URL refers to a directory.
The .htaccess file is an opportunity for the developer to provide server configuration parameters that apply to the directory it is in and all subdirectories.

how to hide files in the www directory

Is it possible to hide a folder from the www directory so that the php files will not be seen if you access it through a web browser?
I'm doing this because I'm not yet good enough to secure those files and the mysql database that they are manipulating.
Or even a trick that would make the web browser not to be able to access the localhost is fine. Please
If you have a directory and you don't want Apache being able to serve any file that's in it, you can create a .htaccess file in that directory, containing :
Deny from all
This will make sure Apache refuses serving any file from that directory -- but they will still be accessible by PHP scripts running from another directory or from the command-line.
If you want Apache to be able to serve the files, but not list the content of the directory when a user accesses that directory without any filename in the URL, you can use this in your .htaccess file :
Options -Indexes
This will disable listing of files inside the directory that contains the .htaccess file -- but will not prevent Apache from serving the files themselves.
Just put the files outside of the document root and include them from there.
A very simple trick if you don't have Apache, hence no access to .htaccess (that sounds like I'm repeating myself), just create a file index.htm or index.html containing NOTHING. Any attempt to access that folder will just show a blank page.

Categories