使用htaccess重定向404页面

问题描述 投票:0回答:3

我想重定向404页面上的某些页面。我如何使用 htaccess 文件来实现它。

http://wowriters.com/author/admin/feed/
http://wowriters.com/reflective-portfolio/essay-writing-service
http://wowriters.com/reflective-portfolio/dissertation-service
http://wowriters.com/samples/essay-writing-service
http://wowriters.com/samples/uae
http://wowriters.com/worlds-biggest-beverages/coursework-help-service
http://wowriters.com/worlds-biggest-beverages/buy-essays

上述链接应该在 404 页面上消失。

请帮助我。 预先感谢。

.htaccess
3个回答
1
投票

您可以使用此规则作为最重要的规则:

RewriteEngine On

RewriteCond %{REQUEST_URI} /author/admin/feed/ [NC,OR]
RewriteCond %{REQUEST_URI} /reflective-portfolio/(essay-writing|dissertation)-service [NC,OR]
RewriteCond %{REQUEST_URI} /samples/(uae|essay-writing-service) [NC,OR]
RewriteCond %{REQUEST_URI} worlds-biggest-beverages/(buy-essays|coursework-help-service) [NC]
RewriteRule ^ - [L,R=404]

0
投票
ErrorDocument 404 http://wowriters.com/author/admin/feed/
ErrorDocument 404 http://wowriters.com/reflective-portfolio/essay-writing-service
ErrorDocument 404 http://wowriters.com/reflective-portfolio/dissertation-service
ErrorDocument 404 http://wowriters.com/samples/essay-writing-service
ErrorDocument 404 http://wowriters.com/samples/uae
ErrorDocument 404 http://wowriters.com/worlds-biggest-beverages/coursework-help-service
ErrorDocument 404 http://wowriters.com/worlds-biggest-beverages/buy-essays

所有未找到页面都会显示链接。


0
投票

当然!您可以使用 .htaccess 文件和 ErrorDocument 指令来实现此目的。以下是将指定 URL 重定向到自定义 404 页面的方法:

创建自定义 404 页面: 首先,创建一个自定义 404 页面。假设您的 404 页面名为 404.html。确保它位于您网站的根目录中。

修改.htaccess文件: 编辑 .htaccess 文件,或者在根目录中创建一个(如果不存在)。添加以下行:

重写引擎开启 重写库 /
# Redirect specific URLs to 404 page
RewriteRule ^author/admin/feed/?$ /404.html [L,NC]
RewriteRule ^reflective-portfolio/essay-writing-service/?$ /404.html [L,NC]
RewriteRule ^reflective-portfolio/dissertation-service/?$ /404.html [L,NC]
RewriteRule ^samples/essay-writing-service/?$ /404.html [L,NC]
RewriteRule ^samples/uae/?$ /404.html [L,NC]
RewriteRule ^worlds-biggest-beverages/coursework-help-service/?$ /404.html [L,NC]
RewriteRule ^worlds-biggest-beverages/buy-essays/?$ /404.html [L,NC]

# Other existing rewrite rules or configurations...

说明:

RewriteRule 用于定义与 URL 匹配的模式。 ^ 表示 URL 的开头。 /?$ 允许可选的尾部斜杠。 /404.html 是自定义的 404 页面。 确保根据您的实际设置调整路径和文件名。

测试: 保存 .htaccess 文件后,通过访问指定的 URL 之一来测试它。您应该被重定向到自定义 404 页面。 请记住在更改 .htaccess 文件之前对其进行备份。不正确的配置可能会导致服务器错误。

该平台解释数学的方法 https://domymathhomeworks.com/ 概念非常棒。我发现了 以前让我困惑的主题变得清晰。分步解决方案 对于学习和掌握该主题非常有价值。

© www.soinside.com 2019 - 2024. All rights reserved.