Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I installed apache2.2, php5, and mysql all with apt-get install. I am using vmware for a Ubuntu 11.04 VM. I am having trouble getting .htaccess being read in the document root. Here is my apache.conf:

#
# The accept serialization lock file MUST BE STORED ON A LOCAL DISK.
#
LockFile ${APACHE_LOCK_DIR}/accept.lock

#
# PidFile: The file in which the server should record its process
# identification number when it starts.
# This needs to be set in /etc/apache2/envvars
#
PidFile ${APACHE_PID_FILE}

#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 300

#
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
#
KeepAlive On

#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 100

#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 15

##
## Server-Pool Size Regulation (MPM specific)
## 

# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>

# worker MPM
# StartServers: initial number of server processes to start
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadLimit: ThreadsPerChild can be changed to this maximum value during a
#              graceful restart. ThreadLimit can only be changed by stopping
#              and starting Apache.
# ThreadsPerChild: constant number of worker threads in each server process
# MaxClients: maximum number of simultaneous client connections
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_worker_module>
    StartServers          2
    MinSpareThreads      25
    MaxSpareThreads      75 
    ThreadLimit          64
    ThreadsPerChild      25
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>

# event MPM
# StartServers: initial number of server processes to start
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process
# MaxClients: maximum number of simultaneous client connections
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_event_module>
    StartServers          2
    MinSpareThreads      25
    MaxSpareThreads      75 
    ThreadLimit          64
    ThreadsPerChild      25
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>

# These need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

#
# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives.  See also the AllowOverride
# directive.
#

AccessFileName .htaccess

#
# The following lines prevent .htaccess and .htpasswd files from being 
# viewed by Web clients. 
#
<Files ~ "^\.ht">
    Order allow,deny
    Deny from all
    Satisfy all
</Files>

#
# DefaultType is the default MIME type the server will use for a document
# if it cannot otherwise determine one, such as from filename extensions.
# If your server contains mostly text or HTML documents, "text/plain" is
# a good value.  If most of your content is binary, such as applications
# or images, you may want to use "application/octet-stream" instead to
# keep browsers from trying to display binary files as though they are
# text.
#
DefaultType text/plain


#
# HostnameLookups: Log the names of clients or just their IP addresses
# e.g., www.apache.org (on) or 204.62.129.132 (off).
# The default is off because it'd be overall better for the net if people
# had to knowingly turn this feature on, since enabling it means that
# each client request will result in AT LEAST one lookup request to the
# nameserver.
#
HostnameLookups Off

# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here.  If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog ${APACHE_LOG_DIR}/error.log

#
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
LogLevel warn

# Include module configuration:
Include mods-enabled/*.load
Include mods-enabled/*.conf

# Include all the user configurations:
Include httpd.conf

# Include ports listing
Include ports.conf

#
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
# If you are behind a reverse proxy, you might want to change %h into %{X-Forwarded-For}i
#
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\""     vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

# Include of directories ignores editors' and dpkg's backup files,
# see README.Debian for details.

# Include generic snippets of statements
Include conf.d/

# Include the virtual host configurations:
Include sites-enabled/

Here is httpd.conf, please notice the DocumentRoto and the Directory directives.:

DocumentRoot /var/www
<Directory /var>
AllowOverride All
</Directory>
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so 
RewriteLog /var/rewrite.log
RewriteLogLevel 9

Here is the .htaccess file it sits in /var because it is not read if I put it in /var/www:

Options +FollowSymLinks
RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?((?:.+?)[^/])$ /$1/ [L,R=301]

I want this rule to simply append a / at the end of a url if it is not already there. It sort of works... if I go to localhsot/t it takes me to localhost/www/t/ and if I take the / off of that it takes me to localhost/wwww/www/t/ and so on. It keeps adding a /www and a / at the end. I think this has to do with my problem with where the .htaccess file is. I believe it should be in my document root (/var/www) but apache will not read it from here even if I have specified in httpd.conf.

Any Ideas? Some more background and a long back and forth with a very helpful developer: http://stackoverflow.com/questions/11586074/making-rewriterule-to-mock-reddits-or-rails/11586401#comment15335191_11586401

Edit: here is the mod_rewrite log (with debug set to 9):

127.0.0.1 - - [24/Jul/2012:19:11:46 --0500] [localhost/sid#213e6480][rid#2159b028    /initial] (3) [perdir /var/] add path info postfix: /var/www/www -> /var/www/www/r/all/
127.0.0.1 - - [24/Jul/2012:19:11:46 --0500] [localhost/sid#213e6480][rid#2159b028/initial] (3) [perdir /var/] strip per-dir prefix: /var/www/www/r/all/ -> www/www/r/all/
127.0.0.1 - - [24/Jul/2012:19:11:46 --0500] [localhost/sid#213e6480][rid#2159b028/initial] (3) [perdir /var/] applying pattern '^/?((?:.+?)[^/])$' to uri 'www/www/r/all/'
127.0.0.1 - - [24/Jul/2012:19:11:46 --0500] [localhost/sid#213e6480][rid#2159b028/initial] (1) [perdir /var/] pass through /var/www/www
share|improve this question
    
So, i noticed the DocumentRoot and AllowOverride directives... why not use <Directory /var/www> around the AllowOverride directive? –  DerfK Jul 25 '12 at 0:34
    
I have tried that, @DerfK. If I do that the .htaccess file is not read in '/var/www' OR '/var'. –  user779608 Jul 25 '12 at 0:36

2 Answers 2

up vote 0 down vote accepted

You mention using apt-get to install all this, but you don't mention having disabled the default site provided by the Debian packages using a2dissite default, which means that the default settings are still being loaded from /etc/apache2/sites-enabled/default. Part of that default site is:

    <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
    </Directory>

Which is overriding your setting.

Either remove your configuration and edit the default site configuration to use it, or disable the default site and update your configuration to include anything it's missing, and your .htaccess file should start working.

share|improve this answer
    
Thank you. I now have a .htaccess file being read from /var/www. Unfortunately, I am still redirected with a '/www' being added to the beginning of my URL. –  user779608 Jul 25 '12 at 0:55

A tip that may or may not help:

Clear and turn off caching in your browser. I once was tracking down a problem with htaccess and eventually found out that my browser was caching a page. To me it appeared the htaccess was not working or working sporadically until I discovered that.

Might not solve your problem, but a useful tidbit at least.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.