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 gi开发者_运维技巧ven REQUEST_URI matches a filename in the directory, my rules seem not to match the REQUEST_URI.
Information:
- http://sub.domain.tld --> root-directory
- http://domain.tld --> root-directory
- File test.php exists in root-directory with content: print_r($_SERVER['QUERY_STRING']);
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?
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!
精彩评论