То же правило перезаписи Apache работает (соответствует) в VHost, но не в файле ".htaccess":
<VirtualHost *:80>
ServerName 192.168.1.100
ServerAlias example.com
DocumentRoot /test
RewriteEngine On
RewriteRule ^/test.html$ /test2.html
RewriteLog "/tmp/rewrite.log"
RewriteLogLevel 9
<Directory "/">
AllowOverride All
</Directory>
</VirtualHost>
Переписать журнал:
192.168.1.10 - - [13/May/2013:16:19:31 +0100] [example.com/sid#7fd764555ed0][rid#7fd764ad9758/initial] (2) init rewrite engine with requested uri /test.html
192.168.1.10 - - [13/May/2013:16:19:31 +0100] [example.com/sid#7fd764555ed0][rid#7fd764ad9758/initial] (3) applying pattern '^/test.html$' to uri '/test.html'
192.168.1.10 - - [13/May/2013:16:19:31 +0100] [example.com/sid#7fd764555ed0][rid#7fd764ad9758/initial] (2) rewrite '/test.html' -> '/test2.html'
192.168.1.10 - - [13/May/2013:16:19:31 +0100] [example.com/sid#7fd764555ed0][rid#7fd764ad9758/initial] (2) local path result: /test2.html
192.168.1.10 - - [13/May/2013:16:19:31 +0100] [example.com/sid#7fd764555ed0][rid#7fd764ad9758/initial] (2) prefixed with document_root to /test/test2.html
192.168.1.10 - - [13/May/2013:16:19:31 +0100] [example.com/sid#7fd764555ed0][rid#7fd764ad9758/initial] (1) go-ahead with /test/test2.html [OK]
".htaccess файл"
# cat /test/.htaccess
RewriteEngine On
RewriteRule ^/test.html$ /test2.html
Переписать журнал:
192.168.1.10 - - [13/May/2013:16:22:17 +0100] [example.com/sid#7fd76455b7d0][rid#7fd764af0d78/initial] (3) [perdir /test/] strip per-dir prefix: /test/test.html -> test.html
192.168.1.10 - - [13/May/2013:16:22:17 +0100] [example.com/sid#7fd76455b7d0][rid#7fd764af0d78/initial] (3) [perdir /test/] applying pattern '^/test.html$' to uri 'test.html'
192.168.1.10 - - [13/May/2013:16:22:17 +0100] [example.com/sid#7fd76455b7d0][rid#7fd764af0d78/initial] (1) [perdir /test/] pass through /test/test.html
Согласно второму журналу, он ищет "^ / test.html $" в URL "test.html". Невозможно сопоставить его из-за косой черты в шаблоне. Пытаться
RewriteRule ^test.html$ /test2.html
вместо того
RewriteRule ^/test.html$ /test2.html
в вашем файле .htaccess.
Добавьте это над RewriteRule в свой .htaccess:
RewriteCond% {HTTP_HOST} ^ (www.)? / Test / test.html $
Измените путь в соответствии с вашей средой.