[英]Using .htaccess to redirect www URLs to non-www for https
[英].htaccess redirect old URLs to new URLs, http to https, non-www to www?
对于重定向现有网站的新版本的URL,我的要求很高。 目前,我正在强制www并使用以下结构重定向所有链接:
使用以下.htaccess规则:
#Force www in all links
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteCond %{HTTPS_HOST} ^example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
#This rule allows for vanity URLs
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^agents/(.*) /members.php?$1 [l]
RewriteRule ^(.*) /members.php?$1 [L,QSA]
该站点的新版本将在整个站点范围内使用https,应该重定向任何旧链接的新URL结构将如下所示:
https://www.example.com/first-directory/second-directory/member
注意:第三条规则将在新站点上消失,因为我正在使用的框架在后台处理了漂亮的URL。
考虑到站点范围内的SSL,实现对新URL的永久重定向的最佳方法是什么?
尝试以下规则:
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /first-directory/second-directory/$1 [L,R=302]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.