[英]htaccess https://example.com/dash/something link redirect problem
[英]How can i redirect unstructured link like (https://example.com/digital-marketing.php/ercbierubcrei) using .htaccess?
存在非结构化链接问题,例如 ( https://example.com/digital-marketing.php/ercbierubcrei )
如何将其重定向到主根?
我的 .htaccess 不工作,我在 .htaccess 中使用以下代码:-
RewriteEngine On
ErrorDocument 404 /example.com
存在非结构化链接问题,例如 (
https://example.com/digital-marketing.php/ercbierubcrei
)如何将其重定向到主根?
我假设/digital-marketing.php
是您文件系统上的一个文件。 在这种情况下/ercbierubcrei
是附加路径名信息(或path-info )。 默认情况下,PHP 处理程序允许路径信息,因此/digital-marketing.php
仍然提供服务,但位于不同的 URL(如果这就是“非结构化链接”的意思?)。
您可以通过在.htaccess
文件的顶部设置以下内容来简单地禁用这些 URL 上的路径信息:
AcceptPathInfo Off
现在,任何包含路径信息的 URL 都将触发 404,并且您的自定义 404 错误文档将被调用。 (如果您愿意,您仍然可以使用 mod_rewrite 覆盖此行为。)
或者,如果您想将/digital-marketing.php/ercbierubcrei
重定向到/digital-marketing.php
(这就是“将其重定向到主根”的意思吗? *1 ),那么您可以在使用 mod_rewrite 在.htaccess
文件的顶部:
RewriteEngine On
RewriteRule ^(.+?\.php)/ /$1 [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
一个简单的 301 重定向就可以完成这项工作。
redirect 301 /old_url http://www.domainroot.com/
使用您网站的完整网址。 像这样
请参考以下.htaccess
示例:
将http://yourdomain/digital-marketing.php/apple
重定向到http://yourdomain/
:
RewriteEngine On
RewriteCond %{REQUEST_URI} /digital-marketing.php/*
RewriteRule ^ / [L,R=301]
将http://yourdomain/digital-marketing.php/orange
重定向到http://yourdomain/ref?code=orange
:
RewriteEngine On
RewriteCond %{REQUEST_URI} /digital-marketing.php/*
RewriteRule ^digital-marketing.php/(.*)$ /ref?code=$1 [L,R=301]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.