HasWeb Family Forum: HTACCESS introduction - HasWeb Family Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic
HTACCESS introduction Rate Topic: -----

#1 User is offline   The Rabbit 

  • Ultimate HasWebber
  • Group: Admin
  • Posts: 904
  • Joined: 11-September 03
  • Location:Goettingen, Germany

  • Flag Image from 3dflags.com

Posted 05 October 2003 - 10:43 PM

Now it's my turn for a "small" howto:

Some people may allready have noticed that I often refer to a file called

.htaccess

Let me give some basics now:

The .htaccess is a special file which can be best explained as a "config file" for Apache. Apache is the program which actually takes care of ALL webpages on a linux server. So a URL like yourdomain.com/index.html is "processed" by Apache and then sent to the browser. Since noone on a shared host server can change the actual apache settings server wide (Thank god!) you need to tell Apache if you want something special.
The place to do that is the .htaccess file!
(Short note on the side for "windows" slaves: when a file starts with "." then linux considers it as a hidden file, that's why you will never see it in a folder index)

Now we know in general, what it is for. But what can it do?

Some examples (far from a complete list):

- You can use it to protect parts of your Homepage from unauthorized access. You can allow only access to an IP or an IP range. You can also require a login with username and password.

- You can turn the "directory index" off (That is the list you see in your browser if no index.--- file exists in a folder)

- You can change settings to apache-related programs like php

- You can change which "filetypes" are processed by apache or e.g. php

- You can redirect a requested URL (e.g. if you have a subdomain "sub.domain.com" and someone types domain.com/sub he would normally stay in the subfolder. You can "force" him to sub.doamin.com with a redirect)

- You can define "Rewrite rules". This is a very powerful but difficult tool. It basically changes, blocks and/or redirects a URL when certain conditions you have defined are met.


Allright. Now let us talk about "multiple" .htaccess files in different levels of folders:

You can have a .htaccess in EVERY folder of your directory tree and there is a defined system, how they apply. Let us do an example. Let's assume you have these folders:

1) public_html
2) public_html/subdomain
3) public_html/subdomain/private

Let us also assume that /subdomain is what you think it is. It is the folder for this: subdomain.yourdomain.com.

Now you create a .htaccess in all three of these folders. In short I'll call them ht-1 ht-2 and ht-3 below.

So which one "rules"? The answer is simple:

A "higher" .htacces will allways apply to the folder it is in and to all lower folders.
(ht-1 applies to all,
ht-2 to subdomain AND subdomain/private,
ht-3 ONLY to subdomain/private)

A "lower" .htaccess will always dominate a higher one if it has a different setting.

Now if you for example "disable" the directory index in ht-1 and you "enable" it in ht-3 what happens?

- You will NOT get an directory listing for
www.yourdomain.com (= Folder public_html/)
and NOT for
subdomain.yourdomain.com (or yourdomain.com/subdomain).
That is because ht-1 applies to all of these folders.

- But you will get a directory listing for
subdomain.yourdomain.com/private
(or yourdomain.com/subdomain/private)
That is because ht-3 is in this folder that belongs to this URL. Now alltough ht-1 forbids the directory index, ht-3 allows it. Thus you get it! You also would get it for all folders BELOW /private.

Now I'll stop for now since this was ment as an genral intoduction.
My first advice if you want to use the .htacces is to allways make a backup via cpanel - filemanager.
If you use FTP, make sure to enable the "list hidden" switch (often "-la") to see the .htaccess!

To find out about details for the syntax, a google search often does wonders (e.g. ".htaccess deny access")

Any question? (sure...)


:rabbit:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic
Other Replies To This Topic

#2 User is offline   Aric 

  • The Goto Guy
  • View blog
  • View gallery
  • Group: Admin
  • Posts: 4,595
  • Joined: 30-April 03
  • Gender:Male
  • Location:New Jersey, USA
  • Interests:Underwater basket weaving

  • Flag Image from 3dflags.com

Posted 05 October 2003 - 11:28 PM

Nicely done.

As you've so often proved, the .HTACCESS file is capable of all kinds of wonders. I bet if you worked hard enough at it you could get it to make you breakfast in bed each morning. ;-)

Aric
Please report server issues to:
The Hasweb Helpdesk and Client Area

Now Shipping (covers v10 and earlier):
cPanel: A User's Guide
WebHost Manager Administration Guide

#3 User is offline   The Rabbit 

  • Ultimate HasWebber
  • Group: Admin
  • Posts: 904
  • Joined: 11-September 03
  • Location:Goettingen, Germany

  • Flag Image from 3dflags.com

Posted 05 October 2003 - 11:31 PM

Together with a cron job, sure :lol:

#4 User is offline   teejer 

  • Advanced Haswebber
  • Group: Hasweb Family Members
  • Posts: 103
  • Joined: 04-September 03
  • Location:CA - Bay Area
  • Interests:forensics, history, chemisty, working with homeless youth, reforming child welfare systems, advocating a return of parental rights

  • Flag Image from 3dflags.com

Posted 06 October 2003 - 12:23 AM

But can it make perfect eggs??? :D
0

#5 User is offline   Aric 

  • The Goto Guy
  • View blog
  • View gallery
  • Group: Admin
  • Posts: 4,595
  • Joined: 30-April 03
  • Gender:Male
  • Location:New Jersey, USA
  • Interests:Underwater basket weaving

  • Flag Image from 3dflags.com

Posted 06 October 2003 - 12:29 AM

Well, that depends, I think you need to download the "perfectEggs3000" PHP script from http://hotscripts.com/ ;-)


Aric
Please report server issues to:
The Hasweb Helpdesk and Client Area

Now Shipping (covers v10 and earlier):
cPanel: A User's Guide
WebHost Manager Administration Guide

#6 User is offline   The Rabbit 

  • Ultimate HasWebber
  • Group: Admin
  • Posts: 904
  • Joined: 11-September 03
  • Location:Goettingen, Germany

  • Flag Image from 3dflags.com

Posted 06 October 2003 - 12:32 AM

Set the cron job to 8 am monday to friday and run the script for 3 minutes

#7 User is offline   robinvfr 

  • Semi-New HasWebber
  • Group: Hasweb Family Members
  • Posts: 7
  • Joined: 28-May 03

Posted 17 October 2003 - 04:57 PM

Yeah, but...how does it bring the tray to you room?
0

#8 User is offline   The Rabbit 

  • Ultimate HasWebber
  • Group: Admin
  • Posts: 904
  • Joined: 11-September 03
  • Location:Goettingen, Germany

  • Flag Image from 3dflags.com

Posted 17 October 2003 - 05:02 PM

You need the module "eggthrow plus" installed for apache. It will then shoot it with a bow.

eggthrow plus has highly increased aiming accuracy. I tried eggthrow lite once and it allmost killed the neighbors :cat:

:peace:

#9 User is offline   Aric 

  • The Goto Guy
  • View blog
  • View gallery
  • Group: Admin
  • Posts: 4,595
  • Joined: 30-April 03
  • Gender:Male
  • Location:New Jersey, USA
  • Interests:Underwater basket weaving

  • Flag Image from 3dflags.com

Posted 18 October 2003 - 12:46 AM

I think there's a William Tell mod for egg throw plus, too. 100% guaranteed accuracy when targeting. :)
Please report server issues to:
The Hasweb Helpdesk and Client Area

Now Shipping (covers v10 and earlier):
cPanel: A User's Guide
WebHost Manager Administration Guide

#10 User is offline   The Rabbit 

  • Ultimate HasWebber
  • Group: Admin
  • Posts: 904
  • Joined: 11-September 03
  • Location:Goettingen, Germany

  • Flag Image from 3dflags.com

Posted 22 October 2003 - 03:56 PM

But that only works on an
:mac:

:sorry2: for that joke ...

#11 User is offline   Aric 

  • The Goto Guy
  • View blog
  • View gallery
  • Group: Admin
  • Posts: 4,595
  • Joined: 30-April 03
  • Gender:Male
  • Location:New Jersey, USA
  • Interests:Underwater basket weaving

  • Flag Image from 3dflags.com

Posted 22 October 2003 - 05:08 PM

lol!
Please report server issues to:
The Hasweb Helpdesk and Client Area

Now Shipping (covers v10 and earlier):
cPanel: A User's Guide
WebHost Manager Administration Guide

#12 User is offline   andy 

  • Advanced Haswebber
  • Group: Hasweb Family Members
  • Posts: 96
  • Joined: 31-May 03
  • Location:Dublin, Oh, USA

  • Flag Image from 3dflags.com

Posted 23 October 2003 - 03:24 PM

so whats the difference between
Options All -Indexes
and
Options -Indexes
to ask a silly question?
0

#13 User is offline   The Rabbit 

  • Ultimate HasWebber
  • Group: Admin
  • Posts: 904
  • Joined: 11-September 03
  • Location:Goettingen, Germany

  • Flag Image from 3dflags.com

Posted 23 October 2003 - 03:36 PM

http://httpd.apache....s/mod/core.html ;)

Options All sets the "default" of "all options" thus would "reset" everything

1) Options All -Indexes

2) Options -Indexes

3) Options All
Options -Indexes


should all three therefore have the same outcome. But I would just go with 2) since it may be that "All" could change some settings from the "hasweb" default to the "Apache factory settings" ...

#14 User is offline   portstorm 

  • Semi-New HasWebber
  • Group: Hasweb Family Members
  • Posts: 22
  • Joined: 04-November 03
  • Location:/dev/null
  • Interests:Sleep

  • Flag Image from 3dflags.com

Posted 05 November 2003 - 08:56 AM

The Rabbit said:

You need the module "eggthrow plus" installed for apache. It will then shoot it with a bow.

eggthrow plus has highly increased aiming accuracy. I tried eggthrow lite once and it allmost killed the neighbors :cat:

:peace:


God forbid someone try to use eggdrop .. they're eggs would get all hacked up and sent via DCC
one fish two fish red fish blue fish
0

#15 User is offline   The Rabbit 

  • Ultimate HasWebber
  • Group: Admin
  • Posts: 904
  • Joined: 11-September 03
  • Location:Goettingen, Germany

  • Flag Image from 3dflags.com

Posted 30 November 2003 - 08:17 PM

If you still do not have enough from .htaccess ;) try this:

http://hasweb.com/fo...opic.php?t=1413

#16 Guest_raggario_*

  • Group: Unregistered Guests

Posted 23 November 2004 - 07:31 AM

Hello,

First off I want to express my thanks for this thread, it is very informative.

I do however have a question that still lingers unanswered for me, hopefully someone here can help.

I recently learned about ".htaccess" because I was trying to figure out how to block "directory browsing" on my site. In other words, when someone types a URL to a location that does not have an index page, only a folder name, and they end up getting an "Index of/foldername" directory listing, including contents of the directory.

Well I solved that problem by adding the line "Options -Indexes" to my .htaccess file. However when I did that it created a new problem that I do not know how to fix..

I have a version of phpbb installed on my site, and with the new .htaccess option, the index page of my discussion board is no longer loading.. I am only getting the error 500 page.

What do I need to do? Is there just another simple little line that I need to add to my .htaccess file, or is this where it starts getting more complex?

I appreciate any help that might shed some light for me!

The link to my site/discussion board are in my signature.

Thank you,

R.
0

#17 User is offline   Aric 

  • The Goto Guy
  • View blog
  • View gallery
  • Group: Admin
  • Posts: 4,595
  • Joined: 30-April 03
  • Gender:Male
  • Location:New Jersey, USA
  • Interests:Underwater basket weaving

  • Flag Image from 3dflags.com

Posted 23 November 2004 - 11:22 AM

options -indexes should not affect your index.html or index.php documents, but you would get a 500 error if there are problems with what you've added to .htaccess (syntax errors, stray characters, incomplete directives. etc.). Try loading the index again, get the error then look in the CPANEL error log. Most 500 errors get written there with more information about them.
Please report server issues to:
The Hasweb Helpdesk and Client Area

Now Shipping (covers v10 and earlier):
cPanel: A User's Guide
WebHost Manager Administration Guide

#18 Guest_raggario_*

  • Group: Unregistered Guests

Posted 23 November 2004 - 01:08 PM

well I looked in my error logs as suggested, and here is the main part of what it says:

Quote

/public_html/bb/.htaccess: Illegal option AllowOverride


Parts were left out of this line above..

I checked my "bb" directory and noticed that I had left an unnecessary copy of .htaccess sitting in there. I deleted it then retried my site, clicked my own "discussion board" link and still got an error page..

I tried pulling up http://www.rkart.us/bb/index.php in a new window and it loaded perfectly, I knew then that there was nothing wrong with the page, or even my TOP .htaccess for that matter.

I checked the actual link itself to see if there was a problem with it and what I found was that I had written the link to go here: "http://www.rkart.us/bb" and when I changed it to "http://www.rkart.us/bb/index.php" It worked after that again!

So basically I learned here that throwing the "Options -Indexes" directive into my top .htaccess affected how all my links get read. If I do not write out a full link to the actual page in whichever directory, then I will most likely get an error page if the main directory page is named anything other than "index.htm"..

That's all just a guess anyways as to what happened.

Thanks for the suggestion of where to look first Aric.
0

#19 User is offline   Aric 

  • The Goto Guy
  • View blog
  • View gallery
  • Group: Admin
  • Posts: 4,595
  • Joined: 30-April 03
  • Gender:Male
  • Location:New Jersey, USA
  • Interests:Underwater basket weaving

  • Flag Image from 3dflags.com

Posted 23 November 2004 - 02:22 PM

You've probably set up your .htaccess file incorrectly. Post the contents here or PM me the contents.
Please report server issues to:
The Hasweb Helpdesk and Client Area

Now Shipping (covers v10 and earlier):
cPanel: A User's Guide
WebHost Manager Administration Guide

#20 Guest_raggario_*

  • Group: Unregistered Guests

Posted 23 November 2004 - 09:07 PM

I am Very green when it comes to working with .htaccess..

I only started working with it probably three days ago, so please forgive my ignorance friends!

I was experimenting with different directives when I first started manipulating my .htaccess file. I had left a line in that was definitely causing the problem with the discussion board not loading.

Quote

DirectoryIndex detect.htm


How simple was that? Too dammed simple!

You were right Aric it was set up wrong. I was working on some of that stuff at approximately 4:00am so I guess my eyes just glanced right over that little sneaky line without registering!

I took the line out, went back and reprogrammed my link to simply go to "bb/" and it works perfectly :mrgreen:

It would seem that that was the answer, If there is more to it than what I've found then please let me know. I know that I've only touched the very basics of what one can do with their .htaccess file.
0

#21 User is offline   Aric 

  • The Goto Guy
  • View blog
  • View gallery
  • Group: Admin
  • Posts: 4,595
  • Joined: 30-April 03
  • Gender:Male
  • Location:New Jersey, USA
  • Interests:Underwater basket weaving

  • Flag Image from 3dflags.com

Posted 23 November 2004 - 09:35 PM

Yes, give The Rabbit an .htaccess file and he can probably set it up to make you coffee and eggs in the morning and fetch the paper from your yard. ;-)
Please report server issues to:
The Hasweb Helpdesk and Client Area

Now Shipping (covers v10 and earlier):
cPanel: A User's Guide
WebHost Manager Administration Guide

#22 User is offline   The Rabbit 

  • Ultimate HasWebber
  • Group: Admin
  • Posts: 904
  • Joined: 11-September 03
  • Location:Goettingen, Germany

  • Flag Image from 3dflags.com

Posted 24 November 2004 - 06:04 PM

I cought these posts to late ;) Else I would have instictevely asked you if you had changed the default index files :lol:

To late now, eh?

Glad it worked out for you !

#23 User is offline   d-cee 

  • lawlerpopsicles!
  • View blog
  • Group: Hasweb Heavyhitters
  • Posts: 452
  • Joined: 21-August 04
  • Gender:Male
  • Location:Sydney
  • Interests:Computers, Cars, Cameras, Audio, Food and Dining

  • Flag Image from 3dflags.com

Posted 21 August 2005 - 07:54 AM

a question for the rabbit maybe someone else can help me out too

i've got a forum hosted at propertyeco.com

at the moment the forum is hosted in the subfolder /forum

so im using a simple redirect file in index.php of propertyeco.com and it redirs to propertyeco.com/forum

i'd like to know how though, how would i make the .htaccess so that visiting propertyeco.com actuallys reads the files inside /forum while keeping the url the same propertyeco.com and not propertyeco.com/forum
0

#24 User is offline   Aric 

  • The Goto Guy
  • View blog
  • View gallery
  • Group: Admin
  • Posts: 4,595
  • Joined: 30-April 03
  • Gender:Male
  • Location:New Jersey, USA
  • Interests:Underwater basket weaving

  • Flag Image from 3dflags.com

Posted 21 August 2005 - 11:53 AM

Do you have any Gallery 1.5 installs? Gallery does exactly that to make URLs easier to remember (if you allow it), you might try looking to the .htaccess file there for hints. It uses mod_rewrite to do the magic.
Please report server issues to:
The Hasweb Helpdesk and Client Area

Now Shipping (covers v10 and earlier):
cPanel: A User's Guide
WebHost Manager Administration Guide

#25 User is offline   d-cee 

  • lawlerpopsicles!
  • View blog
  • Group: Hasweb Heavyhitters
  • Posts: 452
  • Joined: 21-August 04
  • Gender:Male
  • Location:Sydney
  • Interests:Computers, Cars, Cameras, Audio, Food and Dining

  • Flag Image from 3dflags.com

Posted 21 August 2005 - 07:51 PM

yeh, i know it's mod_rewrite

i just dont know any of the things to write one

and a google on tutorials either overloads me with info (eg. apache docs) or isnt what im after. most are for search engine friendly urls etc.

it's doable because i remember doing it before for one of my mambo installs so it seemed completely transperant and all files were in the root but actually were in /mambo - just cant find the guide i used now =(

will check out the gallery one when im free . its not overly urgent but yeh if someone knows plz help!

thanks
0

#26 User is offline   The Rabbit 

  • Ultimate HasWebber
  • Group: Admin
  • Posts: 904
  • Joined: 11-September 03
  • Location:Goettingen, Germany

  • Flag Image from 3dflags.com

Posted 25 August 2005 - 04:52 PM

Currently (having shifts at the WE) I'm a bit tied but I'll come back to you with an idea ;)

#27 User is offline   d-cee 

  • lawlerpopsicles!
  • View blog
  • Group: Hasweb Heavyhitters
  • Posts: 452
  • Joined: 21-August 04
  • Gender:Male
  • Location:Sydney
  • Interests:Computers, Cars, Cameras, Audio, Food and Dining

  • Flag Image from 3dflags.com

Posted 26 August 2005 - 12:28 AM

appreciate it rabbit!
0

#28 User is offline   oso96_2000 

  • Brand Spankin New HasWebber
  • Group: Hasweb Family Members
  • Posts: 3
  • Joined: 16-August 06
  • Location:México

  • Flag Image from 3dflags.com

Posted 01 December 2006 - 09:39 PM

Hi! I have a question. I'm using a .htaccess file to do a mod_rewrite.. but i'm getting a 500 error page. This only happen on an add-on domain.. because if i use it on a subfolder, iw works well..

Here's the .htaccess that isn't working:

Options FollowSymLinks
RewriteEngine On
RewriteRule ^([a-z0-9_-]+)/?$ index.php?seccion=$1 [NC,L]


And this, is other .htacces that's working in a folder of my domain (not the add-on domain):

Options FollowSymLinks
RewriteEngine On
RewriteRule ^web/?$ index.php [NC,L]
RewriteRule ^web/([a-z0-9_-]+)/?$ index.php?sec=$1 [NC,L]
RewriteRule ^sistema/?$ sistema.php [NC,L]
RewriteRule ^sistema/([a-z0-9_-]+)/email=(.+)/codigo=(.+)/?$ sistema.php?sec=$1&email=$2&codigo=$3 [NC,L]
RewriteRule ^sistema/([a-z0-9_-]+)/?$ sistema.php?sec=$1 [NC,L]


And this is the error I'm getting on the Error Log
Invalid command '\xef\xbb\xbfOptions', perhaps mis-spelled or defined by a module not included in the server configuration


As u can see, is almost the same.. but i can't make it works.. any help? ^^

PS. Sorry for my english

This post has been edited by oso96_2000: 01 December 2006 - 09:40 PM

0

#29 User is offline   Aric 

  • The Goto Guy
  • View blog
  • View gallery
  • Group: Admin
  • Posts: 4,595
  • Joined: 30-April 03
  • Gender:Male
  • Location:New Jersey, USA
  • Interests:Underwater basket weaving

  • Flag Image from 3dflags.com

Posted 02 December 2006 - 12:12 AM

I don't see that error in your error log, and I was unable to find an .htaccess file in any directory with the same options you list above.

The error suggests that when you edited the .htaccess file you saved the file in Windows or DOS format or perhaps accidentally included a non-ASCII character or other extended character.

Still, to know for certain, I'd have to see the .htaccess files. PM me with details if you want to.

Also remember that an .htaccess in public_html take precidence over .htaccess files in subdirectories.

Regards,

Aric
Please report server issues to:
The Hasweb Helpdesk and Client Area

Now Shipping (covers v10 and earlier):
cPanel: A User's Guide
WebHost Manager Administration Guide

#30 User is offline   oso96_2000 

  • Brand Spankin New HasWebber
  • Group: Hasweb Family Members
  • Posts: 3
  • Joined: 16-August 06
  • Location:México

  • Flag Image from 3dflags.com

Posted 02 December 2006 - 01:24 AM

I was writing a PM to you, when i figured something.. i was thinking in what you said:

Quote

The error suggests that when you edited the .htaccess file you saved the file in Windows or DOS format or perhaps accidentally included a non-ASCII character or other extended character.


And i tried something: copy the .htaccess file that works, and edit it with the new options.. and it works! still don't know what happen.. that thing about DOS format imabe.. anyway, thanks very much :)
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users


  • Time Now: Sep 10 2010 06:01 PM