Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess重定向https://www 到https://non-www_.htaccess_Redirect_Mod Rewrite - Fatal编程技术网

.htaccess重定向https://www 到https://non-www

.htaccess重定向https://www 到https://non-www,.htaccess,redirect,mod-rewrite,.htaccess,Redirect,Mod Rewrite,我有一个从所有域到的301重定向。 重定向可用于www.example和所有tld(.com、.eu.net)。 但是,如果没有www,它不会重定向到https。 以下是Mod重写: RewriteEngine on RewriteCond %{HTTPS} =off RewriteCond %{HTTP_HOST} ^www\.example\.de$ [NC,OR] RewriteCond %{HTTP_HOST} ^example\.de$ [NC] RewriteCond %{HTTP

我有一个从所有域到的301重定向。 重定向可用于www.example和所有tld(.com、.eu.net)。 但是,如果没有www,它不会重定向到https。 以下是Mod重写:

RewriteEngine on

RewriteCond %{HTTPS} =off
RewriteCond %{HTTP_HOST} ^www\.example\.de$ [NC,OR]
RewriteCond %{HTTP_HOST} ^example\.de$ [NC]
RewriteCond %{HTTP_HOST} ^www\.example\.at$ [NC,OR]
RewriteCond %{HTTP_HOST} ^example\.at$ [NC]
RewriteCond %{HTTP_HOST} ^www\.example\.eu$ [NC,OR]
RewriteCond %{HTTP_HOST} ^example\.eu$ [NC]
RewriteCond %{HTTP_HOST} ^www\.example\.net$ [NC,OR]
RewriteCond %{HTTP_HOST} ^example\.net$ [NC]
RewriteCond %{HTTP_HOST} ^www\.example\.org$ [NC,OR]
RewriteCond %{HTTP_HOST} ^example\.org$ [NC]
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ https://example.de/$1 [R=301,L]
编辑: 以下是目前为止的工作

RewriteCond %{HTTPS} on [NC]
RewriteCond %{HTTP_HOST} !^example\.de$ [NC]
RewriteRule ^(.*)$ https://example.de/$1 [R=301,L]

RewriteCond %{HTTPS} off
RewriteBase /
RewriteRule ^(.*)$ https://example.de/$1 [R=301,L]

您的规则不会重定向
https
URL,因为您没有使用正确的重写条件。此外,您不需要编写多个条件来测试域名。您不必使用两行
RewriteCond
来测试
www.example.com
example.com
,而可以在类似这样的单一条件下进行测试
RewriteCond%{HTTP\u HOST}^(www\)?example.com$

以下是您的规则的简短版本

RewriteEngine on

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.at$ [OR]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.eu$ [OR]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.org$ [OR]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.net$ [OR]
 # the main domain. redirect www.example.de to example.de
RewriteCond  %{HTTP_HOST} ^www\.example\.at$
RewriteRule ^(.*)$ https://example.de/$1 [R=301,L]

在测试此更改之前,请清除浏览器缓存。

否决投票,没有回答,我爱这个社区……谢谢你,我尝试了它,但出现错误500(脚本失败)@Tobias有一个拼写错误,我已经修复了它。检查更新的版本。谢谢,我会在几分钟内测试它,为什么域example.at会在最后一秒中取代example.de?很好,我认为它可以工作,我会在所有域中测试它。你的代码更快,对吗?