开发者

htaccess / apache automatically mapping to php files?

开发者 https://www.devze.com 2023-01-12 22:55 出处:网络
I\'m working with htaccess in a php application.I want some behavior like this: Send request to mydomain.com/login

I'm working with htaccess in a php application. I want some behavior like this:

  1. Send request to mydomain.com/login
  2. Have htaccess intercept the request to login and send to index.php?ref=login

However I have that all set up and for some reason it automatically sends the mydomain.com/login request directly开发者_如何学Go to login.php without going through index.php.

I think maybe there is some configuration interfering here? For reference my .htaccess looks like this:

Options +SymLinksIfOwnerMatch
RewriteEngine On
Options -Indexes

RewriteRule ^news$ /index.php?ref=news [NC,L]
RewriteRule ^login$ /index.php?ref=login [NC,L]

The news url rewriting works fine and routes it through index.php ... but I have no news.php and suspect that If i did there would be an issue there.

I also apologize if this question is in the wrong spot, I'm not sure if it belongs over at superuser or serverfault.


You likely have MultiViews turned on. When you send a request for /login to the server, it gets handled by mod_negotiation before your RewriteRule is correctly applied.

Since MultiViews is enabled, and the resource /login does not exist, it looks for an existing resource to map it to - In this case, /login.php. This is later passed to your RewriteRule directives, but since they're looking for the original URL, no match is found, and no rewrite is performed.

Disabling MultiViews should fix the problem:

Options -MultiViews
0

精彩评论

暂无评论...
验证码 换一张
取 消