Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

apache2 - mod_rewrite not working

New to Debian (Or Linux in general)? Ask your questions here!
Post Reply
Message
Author
User avatar
Grimnar
Posts: 173
Joined: 2008-03-30 16:24

apache2 - mod_rewrite not working

#1 Post by Grimnar »

Trying to fight some referrer spam I have some rewrite rules that I want to set out in life.
But it turns out my mod_rewrite is not cooperating the way I want.

This is the setup:

Code: Select all

<VirtualHost *:80>
        ServerAdmin admin@domain.tld
        ServerName www.domain.tld
        ServerAlias domain.tld
        DocumentRoot /var/www/domain.tld/

      <Directory /var/www/domain.tld>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride all
                Order allow,deny
                allow from all
      </Directory>
      CustomLog /var/log/apache2/domain_access.log combined

</VirtualHost>

And to test if the rewrite is working Im using this code in /var/www/domain.tld/.htaccess

Code: Select all

RewriteEngine on
RewriteRule testpage\.html http://www.google.com [R]
Now as soon as I enable RewriteEngine on, the domain.tld page gives me Error - Forbidden
And as everyone know, checking error-logs will give some answer. But no, nothing here! This is what error.log gives me:

Code: Select all

192.168.0.20 - - [20/Jun/2012:12:49:04 +0200] "GET / HTTP/1.1" 200 519 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:14.0) Gecko/20100101 Firefox/14.0"
/etc/apache2/mods-enabled:

Code: Select all

lrwxrwxrwx 1 root root  30 Jun 20 12:18 rewrite.load -> ../mods-available/rewrite.load

Code: Select all

cat rewrite.load 
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
So, what is going on here?

Yeah, Tried a2dismod rewrite / a2enmod rewrite - still nothing.

tl;tr Turing RewriteEngine On = breaks server.
:?

User avatar
subhuman
Posts: 360
Joined: 2011-08-20 14:54

Re: apache2 - mod_rewrite not working

#2 Post by subhuman »

i'm not quite certain, but it may help if you swap ServerName and ServerAlias:

Code: Select all

ServerName domain.tld
ServerAlias www.domain.tld
however, you will certainly find the correct answer on http://httpd.apache.org/.

User avatar
Grimnar
Posts: 173
Joined: 2008-03-30 16:24

Re: apache2 - mod_rewrite not working

#3 Post by Grimnar »

haha, THAT was it! God damn! That little detail

User avatar
dasein
Posts: 7680
Joined: 2011-03-04 01:06
Location: Terra Incantationum

Re: apache2 - mod_rewrite not working

#4 Post by dasein »

Grimnar wrote:haha, THAT was it!
People who use search engines to find answers to problems would receive great benefit if you would take a moment to mark your thread as SOLVED. (Edit the subject line of your initial post.)

User avatar
Grimnar
Posts: 173
Joined: 2008-03-30 16:24

Re: apache2 - mod_rewrite not working

#5 Post by Grimnar »

Hold your horses, Im not quite satisfied yet. Something is still breaking the system!

Im planning to have a /var/www/.htaccess as a master .htacess and let everybody else use it iva rewrite inherit.
Thus, I think I need to have the 000-default active, and it seems to break the Rewriteengine.

Is it something wrong here?
(The other vhosts are in /var/www/domain2.tld /var/www/domain3.tld etc.

Code: Select all

<VirtualHost *:80>
        ServerAdmin admin@domain.tld
        DocumentRoot /var/www/
        <Directory />
                Options FollowSymLinks
                AllowOverride All
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride all
                Order allow,deny
                allow from all
        </Directory>
        ErrorLog /var/log/apache2/error.log
        LogLevel debug
        LogFormat "%h %l %u %t \"%r\" %<s %b" common
        CustomLog /var/log/apache2/access.log combined
</VirtualHost>

User avatar
subhuman
Posts: 360
Joined: 2011-08-20 14:54

Re: apache2 - mod_rewrite not working

#6 Post by subhuman »

The DocumentRoot should be specified without a trailing slash.
found in: http://httpd.apache.org/docs/current/mod/core.html - shall we read it to you?

Post Reply