如何在apache重写规则中进行转发?

时间:2013-04-17 18:09:36

标签: apache rewrite

我想将所有请求[domain] /hello.txt转发到[domain] /files/txt/hello.txt 原始网址[domain] /hello.txt仍应显示在浏览器地址栏中。

有关如何在apache重写规则中实现此目的的任何建议吗?

谢谢。

1 个答案:

答案 0 :(得分:0)

通过httpd.conf启用mod_rewrite和.htaccess,然后将此代码放在.htaccess目录下的DOCUMENT_ROOT中:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^(hello\.txt)$ /files/txt/$1 [L,NC]

PS:请注意,我没有在上述规则中使用R标志,因此浏览器中的URI不会更改,Apache将在内部加载/files/txt/hello.txt URI。

相关问题