【发布时间】:2021-04-18 03:48:46
【问题描述】:
使用 .htaccess,我正在尝试重定向到 404,并在我的网站上遵循以下规则,该规则运行良好
RewriteEngine ON
ErrorDocument 404 thedomain.com/404
RewriteCond %{REQUEST_URI} !\.php/?$ [NC]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [QSA,L]
但正如预期的那样,这也会更改/重定向 URL。例如,如果没有名为 dummy.php 的文件名,则 URL 将重定向到 thedomain.com/404。
我怎样才能保留现有的 URL (thedomain.com/dummy) 并重定向到 thedomain.com/404,就像 WordPress 404 页面中发生的那样。
【问题讨论】:
-
这能回答你的问题吗? .htaccess redirect to 404 page RewriteRule
-
感谢您的快速回复,但 URL 仍然更改为 404。顺便说一下,我在规则末尾添加了
RedirectMatch 404 ^/abc/.*$
标签: apache .htaccess mod-rewrite errordocument