我有domain.com和domain.org作为指向同一个vhost的别名。如何使用.htaccess将所有domain.com请求重定向到domain.org?

有帮助吗?

解决方案

您可以使用 mod_rewrite 来执行此操作。

RewriteEngine on
RewriteCond %{HTTP_HOST} !^example\.org$
RewriteRule ^ http://example.org%{REQUEST_URI} [L,R=301]

此规则将每个未发送到 example.org 的请求重定向到同一个。

其他提示

domain.com 的所有www /非www重定向到 domain.org

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.org/$1 [R=301,L]
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top