我使用的是wamp服务器3.0.4和apache 2.4.18版本。我想将404页面重定向到自定义页面。我已启用 LoadModule rewrite_module modules/mod_rewrite.so 在里面 apache/conf/httpd.conf 并在 apache/conf/httpd.conf :
LoadModule rewrite_module modules/mod_rewrite.so
apache/conf/httpd.conf
<Directory "c:/wamp64/www/"> Options +Indexes +FollowSymLinks AllowOverride all #none to all Require local </Directory>
在httpd.vhost中
<VirtualHost *:80> ServerName testblog DocumentRoot c:/wamp64/www/testblog <Directory "c:/wamp64/www/testblog/"> Options +Indexes +FollowSymLinks +MultiViews AllowOverride All Require local </Directory> </VirtualHost>
并重新启动服务器。
在我的htaccess文件中,我有以下代码
ErrorDocument 404 https://www.test.com/not-found.html RedirectMatch 301 /learn https://www.test.com/not-found.html
但无法重定向。我错过了什么
保持mod_rewrite启用,然后在.htaccess文件中尝试以下操作:
在顶部添加以下内容:
RewriteEngine On RewriteBase / RewriteRule ^learn https://www.test.com/not-found.html [R=302,L]
RedirectMatch 使用modalias,因此请确保您已启用它,它应该自动启用,但很少可能不会,因此请启用它并尝试重定向。即使在那之后,如果它不起作用,也要坚持上述方法。如果你有任何问题,请告诉我。
RedirectMatch