Log in

View Full Version : .htaccess



pcbrainbuster
03-10-2007, 02:52 PM
Well hello :),

I have read quite a lot about .htaccess and it's featres but i do not completely understand how to use it...

If i wanted to put restrictions on user ip address and let the rest of the world be able to view it how would i ?

pcbrainbuster
03-10-2007, 04:34 PM
I really DON'T mind havin help :)

BLiZZaRD
03-10-2007, 04:46 PM
add the line to the .htaccess with i.p. address, or domain name, or both:



deny from 71.11.141.
deny from google.com


Also if you want a completely private folder or file add



Deny from all


If you are doing this, this really should be all you are having in your .htaccess :)

pcbrainbuster
03-10-2007, 04:57 PM
Is that all there is to it ?

What connects the file itself to the server (is it automatic) and does the htaccess file apply its "script" to anything below it's directory...

thetestingsite
03-10-2007, 04:59 PM
You will need to place the code that Blizzard posted above in a file named .htaccess (nothing else), and place that in the directory you wish to protect (or limit access to).

Hope this helps.

BLiZZaRD
03-10-2007, 05:02 PM
And yes, that is it. Where ever the .htaccess file is everything below that level will be affected.

If you want to keep someone off your site all together put it outside the root folder.

pcbrainbuster
03-10-2007, 05:05 PM
Yes - thanks :),

But just wondering how do you put the htaccess file above the root ?

thetestingsite
03-10-2007, 05:10 PM
With most webhosts, your root directory is above your www folder (or public_html, or document root). Simply place the htaccess file above that.

pcbrainbuster
03-10-2007, 05:13 PM
So what your saying is that i can in my account put a folder called www and before that put the htaccess file...

BLiZZaRD
03-10-2007, 05:18 PM
no, the www folder (oftentimes called public_html or just root) should already be there.

This is the folder that you upload all your web pages and images and crap into that you want everyone to see when they go to youdomain.com.

through an FTP client or your webhosts admin panel you will be allowed to go one folder up from this directory. place the .htaccess there.

You can also put it just inside the root folder, but there are some that can bypass it when it is on this level.

BLiZZaRD
03-10-2007, 05:21 PM
Here is a photo of my FTP client and note the red circles showing the location on the server of my .htaccess:

thetestingsite
03-10-2007, 05:24 PM
In your case (pcbrainbuster), you will not be able to go a level higher due to the fact that I just set up a directory in my root directory for you. You only have access to your directory and anything below it (any folders or files in that directory).

BLiZZaRD
03-10-2007, 05:53 PM
Oh, my bad. I didn't know you were being his webhost :D

pcbrainbuster
03-10-2007, 06:27 PM
lol thanks for your help guys :), i will work a little on htaccess with tests and all that but it is not that importatnt so i do not really need anything above my root :)

pcbrainbuster
03-10-2007, 06:33 PM
Oh SHOOT, there is a problem ! -
thetestingsite - i can't seem to create a file called .htaccess on your server or on my own (laptop), how am i supposed to do any htaccess tests. any ideas ? :confused:

thetestingsite
03-10-2007, 06:39 PM
thetestingsite - i can't seem to create a file called .htaccess on your server

Well; if you are using the file manager, the reason why you cannot create them is becuase it is disabled (the File Manager software does not allow it). It you were to use FTP, then you could do it.



or on my own (laptop), how am i supposed to do any htaccess tests. any ideas?


If you are using Windows, try the following:

- go to the "Control Panel" and click on "Folder Options".
- Click on the "View" tab
- Uncheck the option that says "Hide extensions for known file types"
- If you would like, also select "Show hidden files and folders".

Hope this helps.

pcbrainbuster
03-10-2007, 06:43 PM
Well i already new about the windows part but thanks anyway :) - now i have to try the ftp way (whats your ftp address)

thetestingsite
03-10-2007, 06:46 PM
Same as the url. Link removed

Just log in using your username and password.

pcbrainbuster
03-10-2007, 07:06 PM
Hmmmm it does not work :( - i got .htaccess part to work but it still let me get to the html file...

BLiZZaRD
03-10-2007, 07:25 PM
post your .htaccess code here, I will check that it is correctly set up for you :)

thetestingsite
03-10-2007, 08:17 PM
I looked at it and it says



deny from all


and that's it. I'm not a htaccess guru, but I believe there is something missing. Thoughts?

pcbrainbuster
03-10-2007, 08:34 PM
How dare you thetestingsite what right do you have !!! :mad:

lol just kidding :) but yeh that is all that says really ...

BLiZZaRD
03-10-2007, 08:57 PM
That's all it needs to say, BUT if thats what you are doing (see my post above) it needs to be:



Deny from all


No extra spaces or carriage returns, and notice the CAPITAL D :)

pcbrainbuster
03-10-2007, 09:06 PM
I tried again and it did not work :(

BLiZZaRD
03-10-2007, 09:11 PM
make sure the file name is .htaccess

NOT .htaccess.txt (don't for get the "dot" at the very begining)

Use notepad, not wordpad.

pcbrainbuster
03-10-2007, 09:33 PM
i have already done that... (just ask thetestingsite lol)

BLiZZaRD
03-10-2007, 09:33 PM
whats the link to your site?

thetestingsite
03-10-2007, 09:36 PM
I think it may be a misconfiguration on the server. Let me play around with it and I'll see if I can get it to work.

pcbrainbuster
03-10-2007, 10:11 PM
well its -http://phphost.smackum.com/pcbrainbuster/Web%20Languages/PHP/Tests/htaccess-test/- with no spaces

thetestingsite
03-11-2007, 01:04 AM
Ok, problem fixed. It was something to do with the server configuration not saving correctly. It is fixed now, and works as it should. Let me know if you need any more help.

pcbrainbuster
03-11-2007, 11:23 AM
OH thanks it works now ! (but be ready for more possible questions!):)

BLiZZaRD
03-11-2007, 11:31 AM
(but be ready for more possible questions!):)

Exactly what goes through my head when the 5 newest post identifier on the main page says "Last post by: pcbrainbuster"

:D

pcbrainbuster
03-11-2007, 11:55 AM
LOL :) - anyway my name is there again because here goes another question :), how do i set the htaccess file to open up another html page on the server is the client types an invalid address under the htaccess file ?

edit// - example say the address is www.chickenlaid.com/cool/butnix.htm and there is a htaccess file at www.chickenlaid.com/cool/ and someone types www.chickenlaid.com/cool/butni.htm (x missing) how would i get a page at www.chickenlaid.com/cool/unknownaddress.htm to come up ?

pcbrainbuster
03-11-2007, 11:59 AM
And oh yeah all the links above are made up

pcbrainbuster
03-11-2007, 12:38 PM
Well you can help me .... There are no restrictions ! :)

BLiZZaRD
03-11-2007, 02:00 PM
What you are looking for is a custom error page. In this instance the page they typed in doesn't exist, which results in an Error 404. There are 2 other main error pages (401, and 403) 403 is forbidden, meaning they don't have access, 401 is incorrect username/password.

in your .htaccess add this:



ErrorDocument 401 /401.shtml
ErrorDocument 404 /404.shtml
ErrorDocument 403 /403.shtml


replacing the /40x.shtml with /unknownaddress.html (per your example above)

pcbrainbuster
03-11-2007, 02:14 PM
It does not seem to work ...

BLiZZaRD
03-11-2007, 02:59 PM
Do you have a file named "unknownaddress.html" uploaded to the server?

BLiZZaRD
03-11-2007, 03:00 PM
Also note the "Deny from all" will over ride any ErrorDocument line you have here, so you need to remove that first.

pcbrainbuster
03-11-2007, 03:05 PM
I don't have a file like that above and i have not got a htaccess file with Deny from all eigther....

Whats wrongs any ideas ?

BLiZZaRD
03-11-2007, 03:24 PM
Well... how do you expect to show "unknownfile.html" if you don't have one?

Make a file that you want people to see instead of the standard 404 error. upload it to your server, and put it's name in the .htaccess inplace of the 404.shtml in my code above.

pcbrainbuster
03-11-2007, 03:27 PM
i replaced unknownfile with something else, isn't that alright ?

Dave99
03-11-2007, 09:31 PM
Suppose I have a subdirectory like this:

www.domain.com/subdirectory

How do I configure things so that this:

subdirectory.domain.com

gets pointed to the actual subdirectory?


Thanks
Dave

BLiZZaRD
03-12-2007, 10:48 PM
i replaced unknownfile with something else, isn't that alright ?

Yes, that is fine. Idealistically though you would name the files 401, 403, 404 dot shtml, as that is what the browser will show on default anyway.

I am not huge on .htaccess, and for you (and Dave99) check out B&T's Site (http://tips-scripts.com) for some great .htaccess lines and how to's.

subdomain and pointer instructions are there too :)