-1

I have a example.com.conf and .htaccess for example.com site.

When I place this following content in .htacess file

RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php

it works. The same rule doesn't work inside the VirtualHost in example.com.conf which is up using sites-enabled in apache ? It throws "Bad Request" errors when using example.com.conf

What is the reason, why is it treated differently ?

2

An htaccess file is basically another way of configuring directives in an identical context to a <Directory> section at that location.

The reason this doesn't work for you is that the mod_rewrite configuration is sensitive to context - what you have there requires some adjustment to work within the <VirtualHost> context instead of an .htaccess or <Directory> context.

To get the failures to stop, you should just need to switch from RewriteRule . index.php to RewriteRule . /index.php - but the context change would also break your use of %{REQUEST_FILENAME}, since it requires the request to have already been mapped to a filesystem location. So I'd say just put the rules inside a <Directory> block within your <VirtualHost>.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.