【问题标题】:Redirecting HTTP requests to HTTPS interferes with my seo friendly url将 HTTP 请求重定向到 HTTPS 会干扰我的 seo 友好 url
【发布时间】:2016-02-18 05:06:35
【问题描述】:

我正在使用 .htaccess 创建对 seo 友好的 url,并将我的 HTTP 请求重定向到 HTTPS

当我不使用 HTTP 到 HTTPS 规则时,我的 url 显示 即http://www.domain.com,当有人点击用户名时,url 变为http://www.domain.com/username

但是当我使用 HTTP 到 HTTPS 规则时,当我单击用户名时它会干扰 url 即https://www.domain.com,当有人点击用户名时,网址将更改为https://www.domain.com/username?d=username

当我使用 HTTP 到 HTTPS 规则时,我想要它,然后单击用户名,我的 url 看起来像 即https://www.domain.com,当有人点击用户名时,网址将更改为https://www.domain.com/username

问题在于https://www.domain.com/username?d=username 网址

这是我的 .htaccess 代码

RewriteEngine On

RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?d=$1


#First rewrite any request to the wrong domain to use the correct one (here www.)
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#Now, rewrite to HTTPS:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

【问题讨论】:

  • 将第一条规则移到底部并清除浏览器缓存

标签: apache .htaccess mod-rewrite rewrite


【解决方案1】:

将您的重定向放在首位并使用 L 标志。如果您使用您的域名,您也可以合并规则。

RewriteEngine On

#redirect to https and/or www/https
RewriteCond %{HTTP_HOST} ^domain\.com [NC,OR]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.domain.com/$1 [L,R=301]

RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?d=$1 [L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-29
    • 2018-07-01
    • 2018-04-28
    • 2012-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-06
    相关资源
    最近更新 更多