404 Error - Apache config and mod_rewrite - Something wrong!

Hello all! I am new to Apache and trying to make it work, so here’s my problem. I have created a rewrite rule, and it is not rewriting.

My folder structure is as follows:

root/
genesis/
index.php
.htaccess

I checked to make sure that the rewrite module is being loaded in my httpd.conf file.

Then, I put the following in my virtual host file:

<VirtualHost *:80>
        DocumentRoot "/Users/barryhjames/Sites/stwilliamtheabbot"
        ServerName stwilliam
        ErrorLog "/Private/var/log/apache2/stwilliam-error_log"
        RewriteLog "/Private/var/log/apache2/stwilliam-rewrite_log"
        RewriteLogLevel 9
        <Directory /Users/barryhjames/Sites/stwilliamtheabbot>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                Allow from all
        </Directory>
</VirtualHost>

And then this is what my .htaccess file looks like:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.+)$ /index.php?url=$1 [QSA,L]

Basically, I want whatever someone types in after /root/genesis/ to re-route to /root/genesis/index.php.

Any help would be much appreciated!

Are you using the latest version of Apache? If so instead of using mod_rewrite use FallbackResource. (Can be defined in .htaccess just the same.)

Otherwise might try this:


RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .? /index.php?url=%{REQUEST_URI} [L,QSA]

Alternatively. Instead of passing “url” in the query string you can use $_SERVER[‘REQUEST_URI’] to get the same thing.

Thus it becomes: RewriteRule .? /index.php [L,QSA]

l_e,

Nicely done!

MB,

mod_rewrite requires AllowOverride ALL so you’ve effectively disabled it. Additionally, RewriteLogLevel 9 is great for following mod_rewrite logic but it should never be used on a production server.

Likewise, if you understand MultiViews (and how to keep away from problems), fine, but it seems to cause more problems than it’s worth (my recommendation is -MultiViews).

Regards,

DK