我想在不使用.htaccess文件的情况下配置mod_rewrite规则。当我在.htaccess文件中放置规则时,它们工作正常,但我更愿意将所有配置保留在/ etc / apache2 / sites-available / [site name]配置文件中。
当我在VirtualHost或Directory指令中放置相同的RewriteRules时,没有任何作用。我究竟做错了什么?以下是我的VirtualHost配置文件中的示例:
<Directory />
Options FollowSymLinks
# AllowOverride is on for the .htaccess files to work
AllowOverride All
RewriteEngine On
RewriteRule ^oldsite\.php$ newsite.php
</Directory>
我想我可能会忽略apache2.conf文件中的一些指令,但我不确定。救命。 :)
答案 0 :(得分:5)
您正在使用RewriteRule
pattern that is meant for an .htaccess file。原因是:
在.htaccess文件中使用重写引擎时,每个目录前缀(对于特定目录始终相同)会自动删除以进行模式匹配并自动添加替换完成后。
请尝试使用完整的网址路径:
RewriteRule ^/oldsite\.php$ /newsite.php