1

我有 2 个附加域,我想将它们用作主域的别名。我的 htaccess 中有这个设置,但它不是 100% 正确的。每当我从两个域之一访问页面时,它总是重定向到主域索引页面。

例如,当它需要重定向到https://www.bumpstudios.co.uk/downloads时,去https://bumpstudios.com/downloads会重定向到https://www.bumpstudios.co.uk/

这是我的 htacess 文件

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews -Indexes
</IfModule>

RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule .* https://www.bumpstudios.co.uk%{REQUEST_URI} [R,L]

RewriteBase /

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

RewriteCond %{HTTP_HOST} ^bumpstudios.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.bumpstudios.com$ [OR]
RewriteCond %{HTTP_HOST} ^bumpstudios.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www.bumpstudios.uk$ [OR]
RewriteCond %{HTTP_HOST} ^bumpstudios.co.uk$
RewriteRule (.*)$ https://www.bumpstudios.co.uk/{REQUEST_URI} [R=301,L]
</IfModule>
4

2 回答 2

1

经过更多的摆弄,现在问题似乎得到了解决。我删除了 RewriteBase / 并将域 rewriteCond 规则放在顶部附近。似乎已经成功了。这是修改后的版本

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews -Indexes
</IfModule>

RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule .* https://www.bumpstudios.co.uk%{REQUEST_URI} [R,L]

RewriteCond %{HTTP_HOST} ^bumpstudios.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.bumpstudios.com$ [OR]
RewriteCond %{HTTP_HOST} ^bumpstudios.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www.bumpstudios.uk$ [OR]
RewriteCond %{HTTP_HOST} ^bumpstudios.co.uk$
RewriteRule (.*)$ https://www.bumpstudios.co.uk/$1 [R=301,L]

# RewriteBase /

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
于 2020-11-03T13:10:52.663 回答
0
RewriteCond %{HTTP_HOST} ^bumpstudios.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.bumpstudios.com$ [OR]
RewriteCond %{HTTP_HOST} ^bumpstudios.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www.bumpstudios.uk$ [OR]
RewriteCond %{HTTP_HOST} ^bumpstudios.co.uk$
RewriteRule (.*)$ https://www.bumpstudios.co.uk/$1 [R=301,L]

这可以简化......而不是匹配所有不应该匹配的域/主机名,您可以简单地使用否定条件(!前缀)并匹配单个规范主机名。

例如:

 RewriteCond %{HTTP_HOST} !=www.bumpstudios.co.uk
 RewriteRule (.*) https://www.bumpstudios.co.uk/$1 [R=301,L]

如果不是,www.example.co.uk则重定向到www.example.co.uk. 这使用字典字符串比较(=前缀),而不是正则表达式。所以不需要转义文字点(上面的正则表达式中缺少的东西)。

RewriteRule (.*)$ https://www.bumpstudios.co.uk/{REQUEST_URI} [R=301,L]

你缺少一个%from %{REQUEST_URI}

但正如您所发现的,这些指令的顺序很重要。

于 2020-11-03T16:18:19.327 回答