一封电子邮件与错误的链接输出(https://www.digitalmarketer.com/digital-marketing/content-marketing-strategy/////////////到(https://www.digitalmarketer.com/digital-marketing/content-marketing-strategy/),但是无论我尝试什么,重定向都无法正常工作。
他们还希望将其重定向到始终在开始时始终具有https:///www,并且永远不会在末尾具有index.html,因此我已经在.htaccess文件中:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^content-marketing-strategy/index.html$ /digital-marketing/content-marketing-strategy/? [L,R=301]
我已经尝试添加新的重写,但这不起作用:
RewriteRule ^content-marketing-strategy//$ /digital-marketing/content-marketing-strategy/? [L,R=301]
我是Apache和重定向的新手,因此对任何帮助都非常感谢!谢谢!
编辑:请注意,这是在数字营销文件夹(https://www.digitalmarketer.com/digital-marketing/.htaccess)内的.htaccess文件中应用于数字营销文件夹。
您可以在其他规则的末尾使用插入规则将多个//
剥离到/
中:
RewriteCond %{THE_REQUEST} //
RewriteRule ^.*$ /digital-marketing/$0 [R=301,L,NE]
Apache会自动将多个//
剥离为RewriteRule
的模式中的一个,因此捕获的值$0
将将所有//
转换为/
您可以编写通配符表达式以删除落后的斜线。以下将匹配在前向斜线中拖动的任何HTTP或HTTPS URL,并从该URL中删除所有后退斜线:
RewriteRule ^(.*)/+$ $1 [R=301,L]
以及更多使用301重定向的方式,请参见更多此处:最佳实践:301重定向http to https(标准域)
祝你好运!
我看不到编写规则不会重写的方式。但是,您有多个规则,其中L标志可能会在更早的时间上停止在重写上处理。从文档
[l]标志使mod_rewrite停止处理规则集。在大多数情况下,这意味着如果规则匹配,则不会处理其他规则。 (https://httpd.apache.org/docs/current/rewrite/flags.html)。
您可以尝试此页面http://htaccess.mwl.be/一起测试所有规则。您可能必须重写它们以与该页面一起使用,它不知道您的.htaccess文件的级别,因此您必须重写所有规则以从根部触发:例如:RewriteRule ^digital-marketing/content-marketing-strategy//$ /digital-marketing/content-marketing-strategy/? [L,R=301]