apache - 产品名称的旧 http 到 https 的 seo url 不起作用,规范 url 仍在 http 而不是 https

标签 apache .htaccess mod-rewrite redirect seo

我在将 Opencart 中的 seo 友好 URL 从旧 http 应用到新 https 时遇到问题。

以前我们有很好的 seo url,比如 domain.com/productname 但上个月我们为我们的网站购买了 ssl 证书,现在所有的 url 现在都是 https 版本,所以这些产品页面已经改变了它的格式,例如从 http://domain.com/productname如果你点击链接,它现在像 opencart 中的 https://www.domain.com/index.php?route=productname 一样困惑。

我只是想消除这个 index.php?route= url 参数,以便所有链接都变成 domain.com/productname。我也确实尝试过 GWT 来获取它而不是重定向 URL。我还检查了 header 状态为 200。

规范 url 仍然是 http 而不是 https,一些产品链接仍然指向 http 而不是 https.

到目前为止,我对像关于-我们联系-我们这样的页面没有任何问题,他们工作正常。

下面是我的 .htaccess:

RewriteEngine On
RewriteBase /
#RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
#RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^download/(.*) /index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA] 

#This setting force logo url to it's home page
RewriteCond %{QUERY_STRING} ^route=common/home$
RewriteRule ^index\.php$ https://www.domain.com/? [R=301,L]

#This setting force http to https version
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301,L]

最佳答案

您需要在路由规则之前保留重定向规则:

RewriteEngine On
RewriteBase /

#This setting force logo url to it's home page
RewriteCond %{QUERY_STRING} ^route=common/home$
RewriteRule ^index\.php$ https://www.domain.com/? [R=301,L,NE,NC]

#This setting force http to https version
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301,L,NE]

#RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
#RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^download/(.*) /index.php?route=error/not_found [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

还要确保在新浏览器中对此进行测试以避免旧浏览器缓存。

关于apache - 产品名称的旧 http 到 https 的 seo url 不起作用,规范 url 仍在 http 而不是 https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26508923/

相关文章:

apache - .htaccess 使用子文件夹重写规则强制 SSL

.htaccess - 通配符子域和子文件夹作为 .htaccess 中的参数

php - Centos 7 Apache 如何允许自定义 php.ini 文件

apache - OS X Mavericks 支持 SSL 的虚拟主机

python - 资源暂时不可用 : mod_wsgi (pid=28433): Unable to connect to WSGI daemon process

php - 如何在 Ubuntu 14.04 Lamp Stack 服务器上的 Codeigniter 中设置 .htaccess

c++ - C++ 服务的 mod_gsoap 错误

php - 使用两个查询字符串的 Url 重定向 htaccess

.htaccess ErrorDocument 的相对路径

php - 伪造 cookie 的 'path' - 通过 .htaccess/javascript/或其他方式?