我們將整個站點從http://移動到https://如果您通過https://到達站點,此工作正常。但是,http://上的所有先前緩存的網址(在Google中)都需要重定向。此外,我們以前一直在使用重寫在URL中取出.php文件,並希望保留這一點。但這是我們遇到問題的地方。刪除.php並從http連接發送到https
重定向我們從http到https頁面在整個網站中與下面的htaccess一起使用,但它不會刪除這些重定向上的.php擴展名。
嘗試了這些 Force HTTPS on certain URLs and force HTTP for all others
這裏的問題是
下面是一個例子舊的URL,看看它是如何被使用.PHP不刪除rewriiten。 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]
您可以參考這些鏈接 http://stackoverflow.com/questions/4026021/remove-php-extension-with-htaccess 和 http://stackoverflow.com/questions/4398951/ force-ssl-https-using-htaccess-mod-rewrite –