【问题标题】:.htaccess 301 Redirect with HTTPS.htaccess 301 使用 HTTPS 重定向
【发布时间】:2014-09-08 13:03:33
【问题描述】:

我最近有一个客户站点更改了页面名称,出于 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

两种方式产生相同的结果。有什么想法吗?

【问题讨论】:

  • 什么被重定向到http://examplesite.com:443/newpage1
  • 如果我点击来自https://examplesite.com/oldpage1 的链接,它应该会转到https://examplesite.com/newpage1,但会转到http://examplesite.com:443/newpage1

标签: php apache .htaccess redirect https


【解决方案1】:

您不应将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]

【讨论】:

  • 谢谢,我会在今晚晚些时候的非高峰时段试一试,然后告诉你它是如何工作的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-09-21
  • 1970-01-01
  • 1970-01-01
  • 2018-05-10
  • 1970-01-01
  • 2017-05-03
  • 2017-04-23
相关资源
最近更新 更多