Avatar of hankknight
hankknightFlag for Canada asked on

RewriteCond not working in httpd.conf

This works when I place it in my .htaccess file:
       Options +FollowSymlinks
       RewriteEngine On
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteCond %{REQUEST_FILENAME} !-d
       RewriteRule ^(.*) index.php

However when I add the following (attached) to my http.conf file EVERYTHING is re-written to index.php.

I only want the URL to be re-written if the file or directory does NOT exist.
<VirtualHost example.org:80>
	ServerName example.org
	ServerAlias *.example.org
	 Options +FollowSymlinks
	 RewriteEngine On
	 RewriteCond %{REQUEST_FILENAME} !-f
	 RewriteCond %{REQUEST_FILENAME} !-d
	 RewriteRule ^(.*) /index.php
	ServerAdmin webmaster@example.com
	DocumentRoot /home/example.org/html/
	ErrorLog logs/example.org-error_log
	CustomLog logs/example.org-access_log common

Open in new window

Apache Web Server

Avatar of undefined
Last Comment

8/22/2022 - Mon
Julian Matz

Hi! Have you tried logging (RewriteLog):

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

If you interested in the details: http://httpd.apache.org/docs/2.2/rewrite/rewrite_tech.html

"So, after a request comes in and Apache has determined the corresponding server (or virtual server) the rewriting engine starts processing of all mod_rewrite directives from the per-server configuration in the URL-to-filename phase. A few steps later when the final data directories are found, the per-directory configuration directives of mod_rewrite are triggered in the Fixup phase. "

Basically your conditions are running before apache has actually worked out where the requested file is on the disk, as it hasnt processed any of the per directory configs and aliases etc.

Where as when your .htaccess file runs apache has already worked out there the file requested should physically be located, hence why your .htaccess file works.
Your help has saved me hundreds of hours of internet surfing.