Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.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 如何将www和非www.net转发到www.com?_.htaccess - Fatal编程技术网

.htaccess 如何将www和非www.net转发到www.com?

.htaccess 如何将www和非www.net转发到www.com?,.htaccess,.htaccess,我可以将www.net网址转发到www.com。但是我如何将非www.net转发到www.com呢 下面的代码是我在.htaccess文件中使用的代码,部分工作正常 RewriteCond %{HTTP_HOST} !^www\.example\.net$ [NC] RewriteCond %{HTTP_HOST} ^www\.example\.net$ [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L] 给出你的评论,看起来

我可以将www.net网址转发到www.com。但是我如何将非www.net转发到www.com呢

下面的代码是我在.htaccess文件中使用的代码,部分工作正常

RewriteCond %{HTTP_HOST} !^www\.example\.net$ [NC]
RewriteCond %{HTTP_HOST} ^www\.example\.net$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

给出你的评论,看起来你实际上想要的是任何发往
*.example.net
example.net
的东西,然后转发到www.example.com。这样做的方法是:

RewriteCond %{HTTP_HOST} ^.*\.example\.net$ [OR]
RewriteCond %{HTTP_HOST} ^example\.net$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

使用regexp可能有一种奇特的方法,而不是两个条件,但我建议这是最简单、最直接的方法。

请更清楚地了解您想要什么。是否希望所有命中此目录的请求都被重定向到
www.example.com
。我希望任何进入example.net或www.example.net的内容都能进入www.example.com,这与我刚才所说的完全相反。你把它限制在
example.net
www.example.net
。我不知道为什么我的问题会被问到。我认为主题行非常直截了当。为什么不在www.example.net的.htaccess中做相反的事情呢。这只是我关于Stack的第二个问题。我只是好奇,为什么我的问题得到了两张反对票?