根据工作需要
要将uri /abcdefg.php rewrite成/files/abcdefg.xml
于是在相应的虚机里设置:
RewriteEngine on
RewriteCond %{REQUEST_URI} php
RewriteRule /abcdefg.php /files/abcdefg.xml [L]
但是始终不行
因为/abcdefg.php中其实就是丢出一个Location的头来强迫客户端获取另外一个xml文件,这里是/files/a.xml
假设这里的虚机是www.abc.com
当我telnet www.abc.com 80
再输入
HEAD /abcdefg.php HTTP/1.1
Host: www.abc.com
的时候
返回显示一个“Location:”头,重定向到/files/a.xml
这里显然mod_rewrite没生效
在DocumentRoot目录下
cp abcdefg.php abcdefgh.php
再在配置文件里添加一句:
RewriteRule /abcdefgh.php /files/abcdefg.xml [L]
使之成为这样:
RewriteEngine on
RewriteCond %{REQUEST_URI} php
RewriteRule /abcdefg.php /files/abcdefg.xml [L]
RewriteRule /abcdefgh.php /files/abcdefg.xml [L]
重启apache
再次测试,发现/abcdefgh.php能够正确重定向到/files/abcdefg.xml
但是/abcdefg.php不行
用HTTP命令
HEAD /abcdefgh.php HTTP/1.1
Host: www.abc.com
来看的时候
能正确返回就像是直接请求/files/abcdefg.xml的情况
这样显然mod_rewrite是生效了的
但是/abcdefg.php就是不行
Tags: Tags: apache, Fedora 作者 哈哈
No Comments »