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

I'm trying to get mod_rewrite running for one of my PHP project. Unfortunately it doesn't work, I always get 404 errors. My URLs look like this:
http://admin.domain.com/index.php?page=#1&action=#2
I'd like to rewrite this to the above URL:
http://admin.domain.com/#1/#2/

There are some special cases like when there's no action or additional parameters are specified.

Here's my virtualhost config (edited):

<VirtualHost *:*>
    ServerName admin.domain.com
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www/
    <Directory "/var/www/">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from All
    </Directory>

    ScriptAlias /awstats/ /usr/lib/cgi-bin/
    Alias /awstats-icon/ /usr/share/awstats/icon/

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog /var/log/apache2/error.log

    LogLevel warn
    CustomLog /var/log/apache2/access.log combined

</VirtualHost>

This is the .htaccess content (in /var/www/):

<IfModule mod_rewrite.c>

    RewriteEngine on
    RewriteBase /

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/(.*)/$ index.php?page=$1&action=$2   [L,QSA]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ index.php?page=$1  [L,QSA]

</IfModule>

And here's the error log output when requesting /home/asdf/ or /home/:

[Sat Jun 26 17:46:27 2010] [error] [client ..] File does not exist: /var/www/home
[Sat Jun 26 17:47:09 2010] [error] [client ..] File does not exist: /var/www/home

I'm not very good at regex and mod_rewrite, but it looks like the URL isn't rewritten at all.

share|improve this question

2 Answers 2

up vote 4 down vote accepted

Make sure you have mod_rewrite enabled:

As root:

a2enmod rewrite

Then, restart Apache2, as root:

/etc/init.d/apache2 restart

or

/etc/init.d/httpd restart
share|improve this answer
1  
head -> keyboard –  svens Jun 26 '10 at 16:42
1  
Haha, you're not alone. For one project a few years ago, I spent two hours trying to debug this sort of thing only to realize I didn't have mod_rewrite enabled. It's good for us to have humbling experiences like this every now and again. :) –  EEAA Jun 26 '10 at 16:56

In <Directory /var/www/> the directive AllowOverride None prevent the htaccess file to be used. You must at lease change it to AllowOverride FileInfo

share|improve this answer
    
Just changed it for both / and /var/www/, doesn't make a difference, error log still looks the same. –  svens Jun 26 '10 at 16:12

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.