Forum Moderators: phranque

Message Too Old, No Replies

Problems with RewriteCond .htaccess

         

FredrikMH

12:45 am on Jun 4, 2008 (gmt 0)

10+ Year Member



I have a problems with my .htaccess and it's rewriting. I don't want the file types below to be redirected to the index.php but they are and I don't understand why.

It seems like if the file exists, the file will be loaded, otherwise it's redirected to index.php. I want apache to automatiaclly send 404-error for example someone requests /testfile.xml and it does not exist.

Is this some sort of setting in Apache or why does it do this? Maybe I have missed something simple, I don't know.

The htaccess-file looks like this:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{HTTP_HOST} !^domain\.com [NC]
RewriteCond %{REQUEST_URI} !.*images/.* [NC]
RewriteCond %{REQUEST_URI} !.*adminsection/.* [NC]
RewriteCond %{REQUEST_URI} !.*en/.* [NC]
RewriteCond %{REQUEST_URI} !.*\.htm$ [NC]
RewriteCond %{REQUEST_URI} !.*\.css$ [NC]
RewriteCond %{REQUEST_URI} !.*\.xml$ [NC]
RewriteCond %{REQUEST_URI} !.*\.php.* [NC]
RewriteCond %{REQUEST_URI} !.*\.txt$ [NC]
RewriteRule ^(.*)$ index.php [L]

jdMorgan

2:37 am on Jun 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try:

Options +FollowSymLinks -MultiViews

If that does not help, look for code in other .htaccess files and in server config files that may be rewriting missing files to index.php -- This missing-file rewrite won't happen without 'custom' code being added somewhere; It is NOT a default behaviour of Apache.

Also, you may delete ".*" anywhere it occurs at the start of a pattern and is not preceded by "^", and anywhere it occurs at the end of a pattern and is not followed by "$". In these two cases, ".*" is a waste of characters and CPU time, as it does not change the pattern's behaviour. Example: Your "!.*images/.* [NC]" pattern can equally-well be written as "!images/ [NC]"

If you mean to specify that something must precede or follow the path, then use ".+", not ".*"

Jim

FredrikMH

3:42 am on Jun 4, 2008 (gmt 0)

10+ Year Member



It's the root of the account so no other htaccess file should affect it. So it's either in this file or the configuration file of Apache. But I don't know what to look for in it.

Your suggestions of -MultiViews does not help I'm afraid.

Thanks for the other tip. I know regular expressions but not so much about htaccess and Apache.

Edit: if I remove the .htaccess file I get 404 Error Not Found when trying to access /file.xml.

[edited by: FredrikMH at 3:45 am (utc) on June 4, 2008]

FredrikMH

9:20 am on Jun 4, 2008 (gmt 0)

10+ Year Member



I tried the same htaccess file on another account it works like a charm. So I decided to backup all my files and databases and terminate the acccount through cPanel and create the account and restoring all files.

It works like it should now and I have no idea why this happend, since I created this account just a day ago as well. Something must have gone wrong.