2015-08-18 13 views
0

我們將整個站點從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] 
+0

您可以參考這些鏈接 http://stackoverflow.com/questions/4026021/remove-php-extension-with-htaccess 和 http://stackoverflow.com/questions/4398951/ force-ssl-https-using-htaccess-mod-rewrite –

回答

0

您需要將您的HTTPS重定向到您的規則集的頂部:

RewriteEngine on 

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

## provide ip address redirect to canonical and SEO puproses 
## see: http://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/ [L,R=301] 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html?\ HTTP/ 
RewriteRule ^index\.html?$ https://www.myitalianliving.com/ [L,R=301] 
## added below as in testing we had just the .com/index in the url no  extension. 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\ HTTP/ RewriteRule ^index https://www.myitalianliving.com/ [L,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 [L,NC] 

此外,您需要向索引重定向規則添加條件並使用L標誌(以防萬一)。

+0

已經完成了,但仍然沒有刪除.php文件。 – Puzzel

0

將HTTPS重定向移動到頂部,並在底部重定向。

# To internally forward /dir/file to /dir/file.php 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC] 
RewriteRule ^(.+?)/?$ $1.php [L] 

# Rewrite URLs for processing by router (article.php) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^article/(.+)$ article.php?url=$1 [QSA,L] 

# Rewrite URLs for processing by router (product.php) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^product/(.+)$ product.php?url=$1 [QSA,L] 

# Rewrite URLs for processing by router (page.php) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^page/(.+)$ page.php?url=$1 [QSA,L] 

# Rewrite URLs for processing by router (section.php) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+)$ section.php?url=$1 [QSA,L]