apelliciari
apelliciari

Reputation: 8501

Unexpected htaccess behaviour (mod_rewrite and apache)

Yeah, mod_rewrite is driving me crazy.

Here is the problem:

my htaccess

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

when i try to access the page advantix (so address was www.mywebsite.com/advantix), i'm being redirected to advantix/?url=advantix

Looking at the access log, i have a suspicious 301 in the middle

"GET /advantix HTTP/1.1" 301 335 "-" "Mozilla/5.0"
"GET /advantix/?url=advantix HTTP/1.1" 200 186 "-" "Mozilla/5.0"

There is one important detail: advantix is a directory.

So, if i comment that rule, advantix goes to the folder and list the files.

Why it applies automatically the / if there's a folder matching?

I don't want to reach the folder, i want to reach index.php?url=advantix with a call to advantix.

I have the rewriteLogs too, but they didn't help more. My vhost conf has Directory tag with Options All, if helps, i don't know much about that.

Upvotes: 1

Views: 192

Answers (3)

Yaroslav Sivakov
Yaroslav Sivakov

Reputation: 480

I had a similar problem. My solution is to stop rewriting URL on "bad" paths (directories without slash at the end):

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

Upvotes: 0

Ramesh Tabarna
Ramesh Tabarna

Reputation: 539

Turn off the DirectorySlash Apache directive. This seems to be causing the 301 redirect.

DirectorySlash Off
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]

Upvotes: 1

Eric Petroelje
Eric Petroelje

Reputation: 60498

Try this once:

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

Upvotes: 0

Related Questions