【发布时间】:2015-11-11 14:58:45
【问题描述】:
我们将整个站点从 http:// 移至 https://,如果您通过 https:// 到达该站点,这将正常工作。但是,http:// 上所有以前缓存的 url(在 Google 中)都需要重定向。此外,我们之前一直在使用重写来删除 url 中的 .php 并希望保留它。但这是我们遇到问题的地方。
我们在整个站点中从 http 到 https 页面的重定向与下面的 htaccess 一起使用,但它不会删除这些重定向上的 .php 扩展名。
试过这些 Force HTTPS on certain URLs and force HTTP for all others
问题来了
这是一个旧网址示例,看看它是如何在 .php 未删除的情况下重写的。 http://www.myitalianliving.com/product/1105/translucent-stackable-indoor-outdoor-chair-cooler-by-scab
这里是网站 https://www.myitalianliving.com/
这是 .htaccess 文件
RewriteEngine on
## provide ip address redirect to canonical and SEO puproses
## see: https://stackoverflow.com/questions/9985735/redirect-ip-to-domain
#
#RewriteCond %{HTTP_HOST} ^81\.29\.78\.50$ [NC,OR]
#RewriteCond %{HTTP_HOST} ^([a-z.]+)?myitalianliving\.com$ [NC]
#RewriteCond %{HTTP_HOST} !^www\. [NC]
#RewriteCond %{SERVER_PORT} 80
#RewriteRule ^(.*)$ https://www.myitalianliving.com/$1 [R=301]
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ https://www.myitalianliving.com/ [R=301]
RewriteRule ^index\.html$ https://www.myitalianliving.com/ [R=301]
RewriteRule ^index\.htm$ https://www.myitalianliving.com/ [R=301]
## added below as in testing we had just the .com/index in the url no extension.
RewriteRule ^index https://www.myitalianliving.com/ [R=301]
#
##########################
# Try to remove .php AND send to https from http connection
##########################
Options +SymlinksIfOwnerMatch +MultiViews
#
#### RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
##### RewriteRule ^(.*).php/(.*) $1.php?$2
RewriteRule ^(.*?).php/(.*?) $1.php?$2 [NC]
#
## https://stackoverflow.com/questions/4398951/force-ssl-https-using- htaccess-and-mod-rewrite
#
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
【问题讨论】:
标签: .htaccess http redirect https