dpgu5074 2015-12-15 18:08
浏览 80

使用Htaccess在301之前的多个重写规则

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. While 95% of the URLs are being redirected properly I am finding that my rewrite rules in htaccess aren't catching everything. 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.

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. The goal of the rewrite rules is:

To rewrite any https to 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=****:

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

To remove any references to index.php within the URL:

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

Once these rewrite rules have been applied then link is then redirected based on my 301 link map. As of today these rewrite rules are pretty effective with the exception of the https to http redirect. 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. Any suggestions on how to have the https to http rule work correctly?

  • 写回答

1条回答 默认 最新

  • dongzhi9906 2015-12-15 19:52
    关注

    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] 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答