簡體   English   中英

.htaccess 301使用HTTPS重定向

[英].htaccess 301 Redirect with HTTPS

最近,我有一個客戶端站點出於SEO的目的更改了頁面名稱,並且我們需要在舊鏈接上進行重定向到新鏈接,但是由於某種原因,該鏈接無法正常工作。

.htaccess看起來像這樣:

AddHandler php5-script .php
RewriteEngine On    # Turn on the rewriting engine
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule    ^([^\.]+)$ $1.php [NC,L]

Redirect 301 /oldpage1  /newpage1
Redirect 301 /oldpage2  /newpage2

但是頁面被重定向為:

http://examplesite.com:443/newpage1

我什至嘗試像這樣執行301:

Redirect 301 /oldpage1  https://examplesite.com/newpage1

兩種方式產生相同的結果。 有任何想法嗎?

您不應將mod_rewrite規則與mod_alias規則混合使用,並且還需要在內部重寫規則之前保留外部重定向規則。

嘗試這個:

AddHandler php5-script .php
RewriteEngine On

RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

RewriteRule ^oldpage1/?$ /newpage1 [L,NC,R=301]
RewriteRule ^oldpage2/?$ /newpage2 [L,NC,R=301]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM