HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (
-   General (
-   -   howto add these apache directives? (

Ovidiu 15th February 2007 12:16

howto add these apache directives?
I need one folder i.e. /var/www/web1/web/folder/ to have these directives applied to:


# Disable listing of user files
DirectoryIndex index.php
# Options -Indexes

# Disable php in userfiles directory (recommended!!!!)
# RemoveType php
# <IfModule mod_php4.c>
# php_flag engine 0
# </IfModule>

<IfModule mod_php5.c>
php_flag engine 0

# GET requests only
<LimitExcept GET>
Order Allow,Deny

# This file MUST be in the user files directory in order for bandwidth tracking to work.
# Bandwidth tracking requires your server to have the mod_rewrite module enabled. If you do not have it,
# you will probably get some Internal Server Error messages.
# To disable bandwidth tracking, comment out the lines below that start with Rewrite...or delete everything from here (this line).
# The file.php path MUST be correct in order for bandwidth tracking to work correctly.
# You can use either relative or absolute path. If none works try entering the FULL url
# to file.php as in this example below:
# EXAMPLE ONLY: RewriteRule ^([0-9]+)/(.+)$$1&file=$2 [L,NC]

# Turn on mod_rewrite
RewriteEngine On

# This block will disable image hotlinking. The images will only be viewable
# through a page on your site. This will enable you to put ads or whatever you want
# around the image. If you disable this, the images can be viewed directly.
# To disable, comment out the two lines below.
# Enter your domain name in the line that starts with RewriteCond. Here are some examples:
# Example 1: RewriteCond %{HTTP_REFERER} !^http://(www\.)?celerondude\.com/? [NC]
# Example 2: RewriteCond %{HTTP_REFERER} !^http://(www\.)?google\.com/? [NC]
# If you get a 404 error, enter the absolute path to view.php instead of just ../view.php.
# RewriteCond %{HTTP_REFERER} !^http://localhost/? [NC]
# RewriteRule ^([0-9]+)/(.+)$ ../view.php?userid=$1&file=$2 [L,NC]

# Use the uploader to view the image instead of viewing it directly.
# If you get a 404 error, enter the absolute path to view.php instead of just ../view.php.
RewriteRule ^view/([0-9]+)/(.+\.(jpe?g|gif|bmp|png))$ ../view.php?userid=$1&file=$2 [L,NC]

# Very important, do not remove. Required for bandwidth tracking.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^([0-9]+)/(.+)$ ../file.php?userid=$1&file=$2 [L,NC]
btw. the subdomain serves its files from this folder by an entryinside .htaccess using a rewrite.

can you give me some hints? maybe some parts of the directives are unnecesary? I am using a perfect debian 3.1 install with latest ispconfig.

omni 15th February 2007 15:59

I ran into something like this yesterday, hopefully this fix works for you as well...

In IPSConfig, In the root of your intended site, at the bottom look for the ' Apache Directives (Optional)' box. Input the following.


<Directory '/var/www/web2/web/gallery'>
  AllowOverride Options FileInfo

Except change the directory path to the one you need. Then, make a .htaccess file with what you need (as you posted above).

Ovidiu 15th February 2007 22:16

I was not sure if I could input all that stuff above into the directives fields...

SO if I got you right, by inputting what you said in the directives field, I could then use this .htaccess I pasted above?

omni 15th February 2007 22:26

from what I understand, yes.

and if it doesn't work... just delete the .htaccess and the apache directives and try something else.

Ovidiu 16th February 2007 00:10

I was just concerned about security, as this is a file uploading / sharing application, so I really wanted to use those directives inside a .htaccess file to turn php off for the uplaod folders...

btw. the rewrite stuff works inside the .htaccess its just these:


# Disable php in userfiles directory (recommended!!!!)
# RemoveType php
# <IfModule mod_php4.c>
# php_flag engine 0
# </IfModule>

<IfModule mod_php5.c>
php_flag engine 0

# GET requests only
<LimitExcept GET>
Order Allow,Deny
that give me errors if I put them inside .htaccess files.

I'll try your advice tomorrow, going to bed now.

Ovidiu 16th February 2007 09:12

somethign is wrong around here, do I have to cut away the ' ' around the path of the directory? I tried cutting them away, ispc saves my directive without error but when I go to test the site I am talking about, I get an 500 server error without modifying my .htassess file !? very strange, here is how my .htaccess looks like:


DirectoryIndex index.php
# Options -Indexes

# These might give you an error if PHP is not installed as a module.
# php_value upload_max_filesize 200M
# php_value post_max_size 200M
# php_value short_open_tag 1
# For public uploader
RewriteRule ^register/?$ account.php?action=register [L,NC]
RewriteRule ^login/?$ account.php?action=login [L,NC]
RewriteRule ^pupload/?$ public.php [L,NC]
RewriteRule ^pupload/browse(/([0-9]+))?/?$ public.php?action=browse&page=$2 [L,NC]
RewriteRule ^pupload/view/([0-9]+)/?$ public.php?action=view&upload_id=$1 [L,NC]
RewriteRule ^pupload/manage/([0-9]+)/([0-9a-z]+)/?$ public.php?action=manage&upload_id=$1&key=$2 [L,NC]
RewriteRule ^myfiles(/(.*))?$ myfiles.php?folder=$1 [L,NC]
RewriteRule ^upload(/(.*))?$ upload.php?upload_to=$1 [L,NC]
RewriteRule ^members/?$ browse.php [L,NC]
RewriteRule ^members/([0-9]+)/?$ browse.php?page=$1 [L,NC]
RewriteRule ^members/public/?([0-9]+)?/?$ browse.php?public=1&page=$1 [L,NC]
RewriteRule ^members/info/([0-9]+)$ browse.php?action=info&userid=$1 [L,NC]
RewriteRule ^members/browse/([0-9]+)/?(/.+)?$ browse.php?action=browse&userid=$1&folder=$2 [L,NC]
#RewriteRule ^([a-z0-9\_]+)/?$ browse.php?action=browse&username=$1 [L,NC]
you see I commented out some lines and have it working without the directives. If I add in the directive you gave, using this same .htaccess it stops working...

till 16th February 2007 09:15

Please have a look at the apache error log of the website to get a detailed error message for you 500 error.

Ovidiu 20th February 2007 09:45

3 Attachment(s)
ok, I enabled this line: Options -Indexes in the .htaccess and get 500 error

Quote:||||-||||62.159.242.*** - - [20/Feb/2007:08:09:10 +0100] "GET / HTTP/1.1" 500 - "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0"
but this looks strange: why does it say if the url I am trying to reach is

ok, I just skipped these problems and uploaded an image, which went fine but when trying to view the uploaded image I get an error 500 too, but in the logfile it says error 404 ???

Quote:||||-||||62.159.242.*** - - [20/Feb/2007:08:18:03 +0100] "GET /public/pview/1/netstat-day.png HTTP/1.1" 404 - "" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0"
hmm... I think the problem might not be with these apache directives... I just took out this:

<Directory /var/www/web5/filehosting>
AllowOverride Options FileInfo
and still the same errors...

Ok if someone wants to test, here is the link to the site: and I will attach the .htaccess files here for reviewing. Currently I have only this directive inside my apache directive field in ispc:

Options FollowSymLinks
<Directory /var/www/web5> AllowOverride All
as this subdomain is part of a bigger thing that needs this directive.

The bigger thing is handling all subdomains via wildcard domain, only filehosting is excluded and it seemed to work fine, but where do you think these 500 errors come from? why would there be a not involved in the logfiles?

the main htaccess file is inside the root of this subdomain, the public one is inside the folder with public uploaded files and the userfiles one is inside the folder containing users files

commented these:

<IfModule mod_php4.c>
php_flag engine 0
out - now the public upload works, you see the thumbnails but the links to the original sized pictures doesn't work.

falko 21st February 2007 23:42

Is a Co-Domain of the web site, or is it a web site of its own?

Ovidiu 22nd February 2007 08:44

it is a subdomain which gets redirected via .htaccess to its own folder


RewriteCond %{HTTP_HOST}
RewriteCond %{REQUEST_URI} !filehosting/
RewriteRule ^(.*)$ filehosting/$1 [L]
but there is now www host, I dont use it and this domain doesn't even work with it, I never configured it anywhere...

All times are GMT +2. The time now is 03:08.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.