HTTPS重定向中断重写规则

时间:2018-11-14 22:02:43

标签: .htaccess redirect https

尝试理解重定向的确切过程时遇到了一些麻烦。

这很好:

RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]

# redirect to http subdomain
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{HTTP_HOST} ^www\.m\.pets4you\.com$ [NC]
RewriteRule ^(.*)$ http://m.pets4you.com/$1 [L,R=301]


##################################
RewriteRule ^dogs/(.*).htm?$ breeds.php?page=$1 [L]
RewriteRule ^cats/(.*).htm?$ breeds.php?page=$1 [L]
RewriteRule ^(.*).htm?$ pets4you.php?page=$1 [QSA,L]

但是。。。

RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]

# redirect to http subdomain
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{HTTP_HOST} ^www\.m\.pets4you\.com$ [NC]
RewriteRule ^(.*)$ https://m.pets4you.com/$1 [L,R=301]

##################################
RewriteRule ^dogs/(.*).htm?$ breeds.php?page=$1 [L]
RewriteRule ^cats/(.*).htm?$ breeds.php?page=$1 [L]
RewriteRule ^(.*).htm?$ pets4you.php?page=$1 [QSA,L]

重定向到: https://m.pets4you.com/pets4you.php?page=https://m.pets4you.com/dogs/breedname.htm

任何想法为何? 它会忽略前两个规则,而直接转到最后一个规则。

我确实知道一种解决方法,但是需要重写php代码以使其达到worpdress样式,并更改.htaccess。

该网站已经过时且过时,将由实际的wordpress网站取代。但是目前,我被要求对此站点执行此操作。也是第一次遇到这种问题。

我个人鄙视.htaccess,因为它不是我的最佳选择。任何帮助将不胜感激。 谢谢!

1 个答案:

答案 0 :(得分:0)

和往常一样,当我问一个问题时,我就将其解决。一些没有https的硬编码URL会引起问题。忘记查看主索引页面。因为我通常将URL作为PHP变量。