.htaccess

tomjkear

New Member
Messages
46
Reaction score
0
Points
0
New to hosting online.

How is it best to set the default pages for the entire domain?

I want people to be redirected to the index.php in the root directory from wherever someone tries to access my site.

For example, if someone goes to www.easyrda.elementfx.com/pages/ then they will by redirected to the root index.php.

Can I do this with a single .htaccess or do I need to place one, along with a redirect, in each of the subdirectories.

Cheers,
TK
 

crisp

New Member
Messages
85
Reaction score
0
Points
0
That'll mean no-one can access any page except index.php though wont it? as soon as they try to go from www.easyrda.elementfx.com/index.php to www.easyrda.elementfx.com/pages/ they'll end up back at index.php again unless you include some sort of referer check, to make sure they came from index.php in the first place.

Why would you wanna do that? if someones links to a page on your site, users will have to go looking for it once they've been redirected to the front page, and again, they'd never get there as it'll always redirect back ?

If you don't want people viewing pages, apply a password to the relevent folders or consider some sort of login system to allow access. I may just be tired, it's been a long day, but I don't understand why you'd want that behaviour?
 

tomjkear

New Member
Messages
46
Reaction score
0
Points
0
That'll mean no-one can access any page except index.php though wont it? as soon as they try to go from www.easyrda.elementfx.com/index.php to www.easyrda.elementfx.com/pages/ they'll end up back at index.php again unless you include some sort of referer check, to make sure they came from index.php in the first place.

Why would you wanna do that? if someones links to a page on your site, users will have to go looking for it once they've been redirected to the front page, and again, they'd never get there as it'll always redirect back ?

If you don't want people viewing pages, apply a password to the relevent folders or consider some sort of login system to allow access. I may just be tired, it's been a long day, but I don't understand why you'd want that behaviour?

No no, I was under the impression that the .htaccess file simply defines the default page that should be viewed, by using the following line:
DirectoryIndex file.html

What I was intending is that when someone enters an incomplete URL such as www.easyrda.elementfx.com/pages/ which does not define a particular page, only a directory, then they are redirected to the default page, instead of seeing the directory listing.

Cheers,
TK
 
Last edited:

crisp

New Member
Messages
85
Reaction score
0
Points
0
Ah, try adding a slash to the front of index.php so it's /index.php
 

tomjkear

New Member
Messages
46
Reaction score
0
Points
0
Ah, try adding a slash to the front of index.php so it's /index.php

That will work for the root directory only, otherwise the entire directory path is appended to the URL.
I want it to be global and work throughout the entire domain.
Maybe I just need a seperate .htaccess for each directory!?
 

woiwky

New Member
Messages
390
Reaction score
0
Points
0
As far as I know, this behavior is already defined in the server's httpd.conf file(which we don't have access to). I myself have never had to make any changes for this to occur. If for some reason it isn't working for you, then try adding this to the .htaccess file in your public_html directory(subdirectories should inherit):

DirectoryIndex index.php

You should be able to add other files as well like this:

DirectoryIndex index.php index.html index.htm

Just note that whichever one it finds first in the order of left to right is the one that will be displayed.
 

marshian

New Member
Messages
526
Reaction score
9
Points
0
You don't have to mess around with the .htaccess for making your default pages in each directory "index.php" (or .html, etc)
By default, if you try to access any directory without specifieing a page, you always get redirected to the index page.
Unless you want to use a page other then index.something, you don't need to use .htaccess

Note: if you have multiple pages called "index.something" eg "index.html" and "index.php", then it depends on the server configuration to see which one will be send out. In that case, it could be useful to use .htaccess

Marshian
 

rockee

New Member
Messages
120
Reaction score
0
Points
0
Every directory on your site should have an index file if you do not want a directory listing displayed.

This index file can be a blank index.html file or it can contain a clickable link to your home page or it can include an instant redirect to your home page.

Example 1
For a clickable link index.html that you can edit to suit your site's look and feel then just copy it into every directory you want not to have a directory listing.
Code:
<html>
<head>
<title>Private Directory</title>
</head>
<body>
<div align="center">
<b><font size="6" color="#FFFFFF">
<span style="background-color: #000000">Hello, this is a private directory.</span>
</font></b>
<br>
<br>
<a href="http://www.easyrda.elementfx.com">Click here to go to my Home Page</a>
</div>
</body>
</html>

Example 2
For an instant redirect to your home page you can use a meta tag to instantly refresh the page to go to your home page and again this can be copied into every directory you don't want to list of files displayed.
Code:
<html>
<head>
<title>Private Directory</title>
<meta http-equiv="refresh" content="0;url=http://www.easyrda.elementfx.com/index.php">
</head>
<body>
</body>
</html>
These 2 methods actual help, in a small way, to secure your site from directory sniffers.

You can of course go down the .htaccess path if you wish but again this can only be done by adding a more complicated .htaccess file in every directory you don't want a listing of files displayed, but IMHO the above methods are much easier and if you wish you can actually let people know they are accessing a directory that is not to available for listing files.
This Google search will give some .htaccess redirect tips.

HTH

Regards,
Rocky
 
Top