我如何使用 .htaccess 重定向非结构化 link,例如 (https://example.com/digital-marketing.php/ercbierubcrei)?

How can i redirect unstructured link like (https://example.com/digital-marketing.php/ercbierubcrei) using .htaccess?

存在非结构化 link 问题,例如 (https://example.com/digital-marketing.php/ercbierubcrei)

如何将其重定向到主根目录?

我的 .htaccess 不工作,我在 .htaccess 中使用以下代码:-

RewriteEngine On
ErrorDocument 404 /example.com

一个简单的 301 重定向就可以完成这项工作。

redirect 301 /old_url http://www.domainroot.com/

使用您网站的完整 url。像这样

ErrorDocument 404 https://www.yourdomain.com/example.php

请参考以下.htaccess例子:

重定向 http://yourdomain/digital-marketing.php/applehttp://yourdomain/:

RewriteEngine On
RewriteCond %{REQUEST_URI} /digital-marketing.php/*
RewriteRule ^ / [L,R=301]

重定向 http://yourdomain/digital-marketing.php/orangehttp://yourdomain/ref?code=orange:

RewriteEngine On
RewriteCond %{REQUEST_URI} /digital-marketing.php/*
RewriteRule ^digital-marketing.php/(.*)$ /ref?code= [L,R=301]

There is a issue of unstructured link like (https://example.com/digital-marketing.php/ercbierubcrei)

How can I redirect its to main root?

我假设 /digital-marketing.php 是您文件系统上的一个文件。在这种情况下 /ercbierubcrei 附加路径名信息 (或 路径信息 )。默认情况下,PHP 处理程序允许路径信息,因此仍然提供 /digital-marketing.php,但在不同的 URL(如果这就是“非结构化 link”的意思?) .

您可以通过在 .htaccess 文件的顶部设置以下内容来简单地禁用这些 URL 上的路径信息:

AcceptPathInfo Off

现在,任何包含路径信息的 URL 都将触发 404,并且您的自定义 404 错误文档将被调用。 (如果愿意,您仍然可以使用 mod_rewrite 覆盖此行为。)

或者,如果您想重定向 /digital-marketing.php/ercbierubcrei/digital-marketing.php(这就是“重定向到主根目录”的意思吗?*1) 然后你可以使用 mod_rewrite:[=27 在你的 .htaccess 文件顶部附近做类似下面的事情=]

RewriteEngine On
RewriteRule ^(.+?\.php)/ / [R=302,L]

这会将 /<something>.php/<anything> 形式的 URL 重定向到 /<something.php,有效地丢弃 URL.

的路径信息部分

(*1 - 如果“主根”字面意思是站点的文档根,则不推荐这样做. Google 无论如何都可能将其视为软 404。最好是带有有意义消息的自定义 404。)

ErrorDocument 404 /example.com

这看起来不“有效”。 ErrorDocument 指令的第二个参数理想情况下应该是处理错误响应的文档的本地 URL 路径。

例如:

ErrorDocument 404 /error-documents/my-404-error-document.php