.htaccess

Discussion in 'Server Operation' started by Liac, Jun 15, 2007.

  1. Liac

    Liac New Member

    Hello all.

    First of all, I hope this is the right forum. Like the title suggests, this thread is all about .htaccess and the headache it causes for me. :D

    To put it simply: it doesn't work. I have spent almost 2 hours trying to figure out why, googled trying to find a solution, but to no avail.

    Here's my simple .htaccess:
    Code:
    ErrorDocument 404 custom404.php
    
    My server is running on a local machine. I'm using Ubuntu Linux Server 7.04 with auto-configured Apache, PHP and MySQL. I must say, this is my first try with Linux ever (!), so if you give a Linux-specific answer, I'd appreciate if you explain it for a newbie .

    In /etc/apache2/ I have created a link in "mods-enabled" to rewrite.load in "mods-available". I hope that this has loaded the module (and it apparently has since loading it again with "LoadModule rewrite_module modules/mod_rewrite.so" in apache2.conf issues a warning, that it has already been loaded).

    In my apache2.conf, there are also these lines:
    Code:
    AccessFileName .htaccess
    
    (And at the end...):
    Code:
    <directory />
    AllowOverride All
    Options All
    </directory>
    
    When I specify the contents of the .htaccess file ("ErrorDocument 404 custom404.php") directly in apache2.conf, it works perfectly. So I guess I have configured something wrong, so that .htaccess files are just ignored.

    So, how to make .htaccess files work?

    Any help would be really appreciated :)

    Thanks in advance,
    Liac
     
  2. bschultz

    bschultz Member

    Add this:

    Code:
    <Directory "/var/www/web1/web">
    	Options FollowSymLinks
    	AllowOverride All
    </Directory>
    
    To your Apache Directives field in the ISPConfig Control Panel. Of course, change the location of your website directories appropriately...mine are for Debian...not sure where Ubuntu puts it.
     
  3. Liac

    Liac New Member

    Thank you for your reply! I just did that, still doesn't work... I have added
    Code:
    <Directory "/var/www/">
    	Options FollowSymLinks
    	AllowOverride All
    </Directory>
    
    /var/www/ is where I have my HTTP root. .htaccess files are still ignored.
     
  4. bschultz

    bschultz Member

    I'm not positive, but I think you have to have the correct document root listed for the domain you are working on. So in the ISPConfig panel for the domain in question, put the correct directory path (including the web1, web2, etc.). If that doesn't work, there is a thread about this topic here:

    http://www.howtoforge.com/forums/showthread.php?t=12754&highlight=.htaccess
     
  5. Liac

    Liac New Member

    Thanks again for your quick reply.

    The point is, I don't have ISPconfig installed. I haven't even forwarded the HTTP port in my router settings, because I only access the server on my LAN. I want to use it as a "playground" to get familiar with Linux and develop my website, so that I can start right away when I'm renting a web server.

    So the only document root I have is /var/www/. I have put there every file I need (php files, html files) and I can access them perfectly. Yet, .htaccess does not work.

    I hope the problem gets clearer now :)
     
  6. bschultz

    bschultz Member

    Place this (after the spot in your first post about apache2.conf):

    Code:
    <Directory "/var/www/">
    	Options FollowSymLinks
    	AllowOverride All
    </Directory>
    
    under this:

    Code:
    <directory />
    AllowOverride All
    Options All
    </directory>
    
     
  7. Liac

    Liac New Member

    Still doesn't work :(

    I followed your link to the other thread. I commented

    Code:
    #<Files ~ "^\.ht">
    #    Order allow,deny
    #    Deny from all
    #</Files>
    
    out and added

    Code:
    <directory />
    AllowOverride All
    Options All
    </directory>
    
    <Directory "/var/www/">
    	Options FollowSymLinks
    	AllowOverride All
    </Directory>
    
    to my apache2.conf, restarted the server, but it still does not work. It's frustrating. I tried to play around with my settings, even re-installed the server, but to no avail.

    Hopefully you or someone else still has an idea on what to do? :(
     
  8. bschultz

    bschultz Member

    I'm reaching here....but what are the permissions (and ownership) of your .htaccess file?

    Also, run this

    Code:
    httpd -t
    
    as root from command line. That will check the syntax of the apache config file and tell us what (if any) errors there are.
     
    Last edited: Jun 16, 2007
  9. Liac

    Liac New Member

    The permissions of the .htaccess file are 777 (read and write for owner, group and others) and the owner is a user I called "stduser". It's the only activated user (in Ubuntu, the root account is disabled by default. But you can still execute commands that require root access. If you are interested how this works, look here: https://help.ubuntu.com/community/RootSudo).

    Code:
    httpd -t
    
    didn't work. It said "command not found". Instead I tried the following:
    Code:
    apache2 -t
    
    and it said: "Syntax OK". I hope this helps. :confused:
     
  10. bschultz

    bschultz Member

    Then I'm out of ideas...Falko, can you shed some light on this please?
     
  11. Liac

    Liac New Member

    Okay, but still, thank you so much for trying to help me :)

    Take care
     
  12. falko

    falko Super Moderator Howtoforge Staff

    What's the directory where you've put your .htaccess file? Do you use ISPConfig?

    Any errors in Apache's error log?
     
  13. Liac

    Liac New Member

    No, I don't use ISPConfig.

    The directory where I put my .htaccess file (and already have my PHP scripts, etc) is: /var/www/

    Apache's error log is full of errors saying that /var/www/favicon.ico does not exist ;). But apart from that, no errors that refer to .htaccess.

    I just tried "ls -l" in "/var/www/" and the .htaccess file didn't show up. Yet, in my OpenSSH client it shows up and I can even edit it. Could this be the problem--that Apache simply does not see the file? Any ideas on how to fix this problem?
     
  14. falko

    falko Super Moderator Howtoforge Staff

    Files beginning with a dot (like .htaccess) are only shown if you use the -a switch (e.g.
    Code:
    ls -la /var/www
    ). That's the default behaviour and nothing to worry about.

    Do you use Debian or Ubuntu? If so, what's in /etc/apache2/sites-available/default?
     
  15. Liac

    Liac New Member

    I'm using Ubuntu Server 7.04.

    Wow, that led me into the right direction. The first lines were like this:

    Code:
    NameVirtualHost *
    <VirtualHost *>
    	ServerAdmin webmaster@localhost
    	
    	DocumentRoot /var/www/
    	<Directory />
    		Options FollowSymLinks
    		AllowOverride None
    	</Directory>
    	<Directory /var/www/>
    		Options Indexes FollowSymLinks MultiViews
    		AllowOverride None
    		Order allow,deny
    		allow from all
    		# This directive allows us to have apache2's default start page
                    # in /apache2-default/, but still have / go to the right place
                    #RedirectMatch ^/$ /apache2-default/
    	</Directory>
    
    I changed in both the directory / and /var/www "AllowOverride None" to "AllowOverride All" and that did the trick. Thank you so much! :)

    Can you explain why it disregarded the same <directory> tags in httpd.conf AND apache2.conf, while at the same time accepting it, when I change it in the "default" file? What's happening?

    And what's the "default" file for, exactly? Do I have to put additional directives into this file? Or can I get rid of it so that I have only one configuration file, that is, httpd.conf?

    Kind regards.
     
  16. falko

    falko Super Moderator Howtoforge Staff

    The default file contains the default vhost (with the document root /var/www). That's why you must modify that vhost configuration if you put your files into /var/www.
     

Share This Page