.htaccess - htaccess not redirecting all not found page or URL on site to 404 pages
问题描述
Try to set 404 page not found error page by htaccess.
Issue is if we are searching for https://www.rsseosolution.com/suraj.html ... Its redirect perfect to 404.php. But if we are searching for https://www.rsseosolution.com/suraj.php ... Its not redirecting to 404.php and giving showing simple text message "File not found.".
In short problem is if extension is not php then its redirecting fine but if .php then its showing File not found.
ErrorDocument 404 https://www.rsseosolution.com/404.php
Options +FollowSymLinks
RewriteEngine on
# ensure www.
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# ensure https
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule seo-package-(.*)-n-(.*)\.php$ seo-package-detail.php?id=$1&name=$2 [NC,L]
RewriteRule case-studies/(.*)-(.*)\.php$ case-studies.php?project=$1&id=$2 [NC,L]
RewriteRule tutorial/(.*)-(.*)\.php$ tutorial.php?topic=$1&id=$2 [NC,L]
RewriteRule blog-page-(.*)\.php$ blog.php?page=$1 [NC,L]
RewriteRule seo-tutorial-(.*)\.php$ seo-tutorial.php?page=$1 [NC,L]
RewriteRule frequently-ask-question-faq-(.*)\.php$ frequently-ask-question-faq.php?page=$1 [NC,L]
What i am looking for is ....... redirect all not found or wrong URL to 404.php.
What i am missing here.
I think because we are rewriting some URLs with .php extension from htaccess and thats why for PHP its saying file not found but for other its redirecting perfectly to 404.php.
Is there any ways to set 404.php for all not found pages and URL without change any extension (.php) of previous written file by htaccess.
解决方案
问题与您当前在.htaccess
.
问题很可能是由于您的服务器配置和在您的服务器上实现 PHP 的方式。如果文件请求.php
被代理到后端服务器进行处理,就像 FastCGI 类型配置的情况一样,那么这个 404 Not Found 消息很可能来自后端服务器,而不是您的 Apache 服务器。
通常,您可以使用ProxyErrorOverride
反向代理配置中的指令解决此问题:
ProxyErrorOverride On
如果您无权访问主服务器配置,那么您可以在.htaccess
请求发送到代理服务器之前使用 mod_rewrite in 提前触发 404。
例如,在您现有的 mod_rewrite 指令之前:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.php$ - [R=404]
但是,这严格来说是一种“解决方法”,如果您有权访问服务器配置,那么ProxyErrorOverride
最好使用(如上所述)。
在旁边:
ErrorDocument 404 https://www.rsseosolution.com/404.php
通过在指令中指定绝对 URL,ErrorDocument
这会触发错误文档的外部(302) 重定向(附加请求),这通常是不可取的(并且您需要手动设置 404 响应代码)。最好将错误文档作为内部子请求发出:
ErrorDocument 404 /404.php
推荐阅读
- java - Scala Map[String, Int] 类铸造灾难
- asp.net-core - 将 F# ASP.NET Core 应用程序从 .NET 3.1 更新到 5.0
- php - 在 PHP MsSQL 中检查可用性和房间预订
- javascript - 为什么即使我使用 chrome 浏览器,赛普拉斯在 GUI(柏树打开)中的测试通过但在命令行(柏树运行)中失败?
- node.js - 如何设置 --max_old_space_size 以及如何获得实际大小?
- node.js - 无法选择名称中包含数字的“模式”
- python - tensorflow 2,使用张量作为没有for循环的索引
- powerbi - PowerBI + Snowflake:ODBC 连接:DirectQuery
- azure - ARM模板:变量部分中嵌套副本的解决方法
- reactjs - 通过路由器发送数据时遇到问题