1
Dave_L
.htaccess help
  • 2006/7/1 15:19

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


I'm having trouble figuring out the correct syntax for an Apache directive.

I have a directory "one" with subdirectories "two" and "three":

example/one
example/one/two
example/one/three

These are all within the web document root.

I want to allow browser access to example/one/two, but deny browser access to example/one/three.

One way of doing this to to put an .htaccess file in example/one/three with contents "Deny from all". But I'd prefer to place the .htaccess file in example/one instead.

I've made several attempts, but can't figure out the proper directives.

Here's one attempt that's wrong (results in "500 Internal Server Error"):

<Location "^.*/xxx/example/three/.*$">
Deny from all
</Location>


(The "xxx" is not really there, I'm only putting it here to represent the first part of the path.)

Any suggestions on how to fix this?

2
bb2120
Re: .htaccess help
  • 2006/7/1 23:13

  • bb2120

  • Not too shy to talk

  • Posts: 179

  • Since: 2005/7/6 1


I was having a similar problem the other day. It turned out that I had to use my host's control panel to create an .htpasswd file - they do not allow the manual insertion of .htaccess files. Ask your host about it.

3
Dave_L
Re: .htaccess help
  • 2006/7/1 23:29

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


I am my host. It's a dedicated server, and I have admin access.

I can create .htaccess files. It's just figuring out the correct Apache directive that I need help with.

4
Will_H
Re: .htaccess help
  • 2006/7/2 0:03

  • Will_H

  • Friend of XOOPS

  • Posts: 1786

  • Since: 2004/10/10


well its probably not what you were looking for but you could try a url rewrite in the .htaccess.

Basic syntax
RewriteEngine On
RewriteRule 
^initial urltarget?


so heres your outcome

RewriteEngine On
RewriteRule 
^/one/three/$ /one/two/?


Basically what this will do is force browsers into the /one/two/ directory.

sometimes it works best without the trailing slash.

5
Bender
Re: .htaccess help
  • 2006/7/2 0:11

  • Bender

  • Home away from home

  • Posts: 1899

  • Since: 2003/3/10


From all playing around and googling i have done in the last hour i would suspect it needs an override in httpd.conf.

AllowOverride All

Even then i am not sure it will work though since location is in the core docs not listed with an Allow override feature.

Might be worth a try though.


(ever tried to create a file named .htaccess under windows ... well thats why i canĀ“t test it here with xampp and my sites are all shared hosting so i have no access to httpd.conf.

Good luck.
Sorry, this signature is experiencing technical difficulties. We will return you to the sheduled signature as soon as possible ...

6
Dave_L
Re: .htaccess help
  • 2006/7/2 10:30

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


Biteronboard:

I want to deny access to example/one/three completely, not redirect.

Bender:

httpd.conf is already set up to allow override. Otherwise .htaccess files would not work at all.

Creating .htaccess files in Windows is challenging. If I recall correctly, you can create the file from a DOS prompt by renaming another file. Or else I create it on Linux, and then copy it into Windows.

----

I think the approach I'm using is correct. I just need the correct syntax for the Location or equivalent tag.

Thanks anyway.

7
Bender
Re: .htaccess help
  • 2006/7/2 11:08

  • Bender

  • Home away from home

  • Posts: 1899

  • Since: 2003/3/10


I think its not a syntax problem.
From core docs:

Section AllowOverride Directive:

Quote:
Only available in <Directory> sections
AllowOverride is valid only in <Directory> sections specified without regular expressions, not in <Location>, <DirectoryMatch> or <Files> sections.


Quote:
Example:

AllowOverride AuthConfig Indexes

In the example above all directives that are neither in the group AuthConfig nor Indexes cause an internal server error.


Since it seems location is in no group at all it might just not be possible.
Sorry, this signature is experiencing technical difficulties. We will return you to the sheduled signature as soon as possible ...

8
Kmac01
Re: .htaccess help
  • 2006/7/2 18:46

  • Kmac01

  • Just popping in

  • Posts: 4

  • Since: 2006/6/3 2


I did lots of testing on this, but the only way I can get it working is to add the <Directory> directive to the main httpd.conf file for appache. Any directives that seem to apply are only available in the main config file, not .htaccess files. (And you must restart apache for the changes to take effect)

On a side note, when creating files in windows that are for a unix environment I use my favorite text editor PFE32. It will allow you to save files in unix format. It also has tons of useful options like macros. It also runs great from a USB drive so you can always have it with you. You can grab a copy from my downloads section at http://basicstuff.info
Quote:

Creating .htaccess files in Windows is challenging. If I recall correctly, you can create the file from a DOS prompt by renaming another file. Or else I create it on Linux, and then copy it into Windows.

9
Peekay
Re: .htaccess help
  • 2006/7/2 20:59

  • Peekay

  • XOOPS is my life!

  • Posts: 2335

  • Since: 2004/11/20


Quote:

Dave_L wrote:

Creating .htaccess files in Windows is challenging. If I recall correctly, you can create the file from a DOS prompt by renaming another file. Or else I create it on Linux, and then copy it into Windows.


Create the file in any text editor (e.g. notepad)
Select 'File/Save As'.
In the 'Save as type' box select 'All Files (*.*)'
In the 'File name' box change file name to .htaccess
Click Save.

A thread is for life. Not just for Christmas.

10
Kmac01
Re: .htaccess help
  • 2006/7/2 21:09

  • Kmac01

  • Just popping in

  • Posts: 4

  • Since: 2006/6/3 2


Quote:

Peekay wrote:

Create the file in any text editor (e.g. notepad)
Select 'File/Save As'.
In the 'Save as type' box select 'All Files (*.*)'
In the 'File name' box change file name to .htaccess
Click Save.


That works for filename issues, but you still end up with a file in windows format (end of line is CR/LF) whereas unix format the end of line is just a line feed (LF). If you open up a files saves as above with the unix vi it will say [DOS].

Sometimes unix/linux systems will not work properly with these files.

Login

Who's Online

58 user(s) are online (37 user(s) are browsing Support Forums)


Members: 0


Guests: 58


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Jul 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits