简体   繁体   English

带有Htaccess的301之前的多个重写规则

[英]Multiple Rewrite Rules Before 301 With Htaccess

Good Afternoon, 下午好,

A year ago I migrated my domain name to a domain I had purchased. 一年前,我将域名迁移到了购买的域名。 I have kept the old domain active for the purpose of handling the custom 301's for nearly 5000 links that were changed during migration. 我将旧域保持活动状态是为了处理在迁移过程中更改的近5000个链接的自定义301。 While 95% of the URLs are being redirected properly I am finding that my rewrite rules in htaccess aren't catching everything. 虽然正确重定向了95%的URL,但我发现htaccess中的重写规则无法捕获所有内容。 I've researched and tested many different variations with no luck, I'm hoping someone can help. 我没有运气就研究和测试了许多不同的版本,希望有人能提供帮助。

** Remember that my rewrite rules are meant to format the old links before they are eventually redirected to the correct URL on the new domain. **请记住,我的重写规则用于格式化旧链接,然后将它们最终重定向到新域上的正确URL。

My current rewrite rules are: 我当前的重写规则是:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTPS} on [OR]
RewriteCond %{HTTPS} off [NC]
RewriteRule ^(.*)/$ $1 [R=301,L]
RewriteRule ^(.*)RK= /$1 [L,NC,R=301]
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)$ http://newdomain.com/? [R=301,L]
RewriteCond %{REQUEST_URI} ^/$
Rewriterule ^(.*)$ http://newdomain.com/ [L,R=301]

Again, I'm certainly not an htaccess/Apache expert, I've just compiled this list through a lot of trial and error over the past year. 同样,我当然不是htaccess / Apache专家,在过去的一年中,我只是通过大量的试验和错误来汇编了此列表。 The goal of the rewrite rules is: 重写规则的目标是:

To rewrite any https to http: 要将任何https重写为http:

RewriteCond %{HTTPS} on [OR]
RewriteCond %{HTTPS} off [NC]

To remove the trailing slash if present: 要删除尾部斜杠(如果存在):

RewriteRule ^(.*)/$ $1 [R=301,L]

To remove code associated with hacking attempts that attach themselves to the end of certain URLs and look like /RK=0/RS=****: 要删除与黑客尝试相关联的代码,这些黑客尝试将自身附加到某些URL的末尾并看起来像/ RK = 0 / RS = ****:

RewriteRule ^(.*)RK= /$1 [L,NC,R=301]

To remove any references to index.php within the URL: 要删除URL中对index.php的任何引用,请执行以下操作:

RewriteCond %{THE_REQUEST} ^.*/index.php

Once these rewrite rules have been applied then link is then redirected based on my 301 link map. 一旦应用了这些重写规则,便会根据我的301链接映射对链接进行重定向。 As of today these rewrite rules are pretty effective with the exception of the https to http redirect. 到目前为止,这些重写规则非常有效,除了https到http重定向之外。 For whatever reason I cannot get that rule to apply, so any inbound link with https stalls on the "Your connection is not private" screen and does not redirect. 无论出于何种原因,我都无法应用该规则,因此任何带有https的入站链接都会停滞在“您的连接不是私有的”屏幕上,并且不会重定向。 Any suggestions on how to have the https to http rule work correctly? 关于如何使https to http规则正常工作的任何建议?

Change : 变更:

# Do nothing !
RewriteCond %{HTTPS} on [OR]
RewriteCond %{HTTPS} off [NC]

To : 至 :

RewriteCond %{HTTPS} on
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301] 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM