繁体   English   中英

Getting .htaccess redirects from one domain to another to work for WWW ( both http://www. and https://www.), HTTP and HTTPS

[英]Getting .htaccess redirects from one domain to another to work for WWW ( both http://www. and https://www.), HTTP and HTTPS

我有一个重定向场景,我无法绕开我的脑袋。

目标是:

  • old-domain.com/store 需要重定向到 new-domain.com/store
  • Old-Domain 上应保留三个验证脚本。com
  • 从 old-domain.com 到重定向到 new-domain.com 的所有其他内容
  • 这些规则需要适用于所有场景 HTTP、HTTPS 和 WWW(HTTP 和 HTTPS)

我遇到的问题是,当我删除 WWW 重定向时,old-domain.com/store 只会正确重定向到 new-domain.com/store。 我似乎无法让它很好地融合在一起。

这是我所拥有的:

Options +FollowSymLinks
## Rewrite rules
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.old-domain.com$
RewriteRule ^(.*)$ http://old-domain.com/$1 [R=301]
RewriteCond %{HTTP_HOST} ^www.old-domain.com$
RewriteRule ^(.*)$ https://old-domain.com/$1 [R=301]
RewriteCond %{REQUEST_URI} !^/validation-script-1\.html
RewriteCond %{REQUEST_URI} !^/validation-script-2\.html
RewriteCond %{REQUEST_URI} !^/validation-script-3\.html
Redirect 301 /store/ https://new-domain.com/store
RewriteRule ^(.*)$ https://new-domain.com/ [R=301,L]
</IfModule>

我们还尝试了以下方法,但验证脚本停止通过:

Options +FollowSymLinks
## Rewrite rules
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{REQUEST_URI} !^/validation-script-1\.html
RewriteCond %{REQUEST_URI} !^/validation-script-2\.html
RewriteCond %{REQUEST_URI} !^/validation-script-3\.html

# Remove trailing slash from non-filepath urls
RewriteCond %{REQUEST_URI} /(.+)/$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ http://old-domain.com/%1 [R=301,L]

# Include trailing slash on directory
RewriteCond %{REQUEST_URI} !(.+)/$
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+)$ http://old-domain.com/$1/ [R=301,L]

RewriteRule ^/?store https://new-domain.com/store [R=301,L]

# Remove WWW
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [OR,NC]
RewriteRule ^(.*)$ https://new-domain.com/ [R=301,L]

</IfModule>

以下重写规则会将所有 (www.)old-domain.com URL 重定向到https://new-domain.com/除了包含 validation-script-(1|2|3).ZFC35FDC70D5FC69D269883A8 的 URL

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/validation-script-(1|2|3)\.html$
RewriteCond %{HTTP_HOST} ^(www\.)?old-domain\.com$
RewriteRule ^(.*)$ "https\:\/\/new-domain\.com\/$1" [R=301,L]

检查此演示https://htaccess.madewithlove.be?share=f0deda97-dff8-569e-bd6f-411b8a779361

编辑:将old-domain.com/storeold-domain.com/store/重定向到domain.com/pages/store

RewriteRule ^store/?$ "https\:\/\/new-domain\.com\/pages\/store" [R=301,L]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM