lszrh
lszrh

Reputation: 1582

Rule doesn't work for existing files

I want to create a rule for one subdomain which redirects to a file on the root-directory. If the rules don't match the user should be redirected to the original domain.

Both, the subdomain and the domain link to the same directory. But if the first subdir of the given REQUEST_URI matches a filename in the directory, my rules seem not to match the REQUEST_URI.

Information:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^sub\. [NC]
RewriteCond %{REQUEST_URI} ^/([a-z]+)/ [NC]
RewriteRule ^test/ http://domain.tld/ [L,R=301]
RewriteRule ^([a-z]+)/(.*)$ test.php?dir=$1&data=$2 [L]

With http://sub.domain.tld/xyz/something the test.php outputs "dir=xyz&data=something".

But if I use http://sub.domain.tld/test/something I get only a blank page. But this should also output "dir=test&data=something".

What is my mistake? Is it also possible to optimize my rules?

Upvotes: 0

Views: 403

Answers (1)

lszrh
lszrh

Reputation: 1582

Got it! I had to deactivate MultiView which was activated by default. MultiView is useful to call files without extension. Therefor http://domain.tld/file is rewritten to file.EXT (with which extension the file is stored on the server).

My server modified the REQUEST_URI to /file.EXT/subdir/subfile.html if I called a file which was stored on the server.

Example: test.php is a valid file. http://domain.tld/test/something --> request_uri: /test.php/something

Add to your htaccess-file:

Options -MultiViews

to deactivate it and get it working!

Upvotes: 1

Related Questions