dev*_*vin 11 mod-rewrite apache2 virtualhost
我想在不使用.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>
Run Code Online (Sandbox Code Playgroud)
我想我可能会忽略apache2.conf文件中的一些指令,但我不确定.救命.:)
您使用的RewriteRule是用于.htaccess文件的模式.原因:
在.htaccess文件中使用重写引擎时,每个目录前缀(对于特定目录始终相同)将自动删除以进行模式匹配,并在替换完成后自动添加.
因此,请使用完整的URL路径尝试此规则:
RewriteRule ^/oldsite\.php$ /newsite.php
Run Code Online (Sandbox Code Playgroud)