重定向301 www.www.example.com

Ped*_*dro 4 linux apache seo http-status-code-301

我正在使用LAMP服务器,我需要重定向请求,如:

www.www.example.com到www.example.com和其他变体如(wwww.example.com等)

我知道我可以在.htaccess中完成它,但我不知道我应该用它来表示所有这些可能性的正则表达式.

或者有什么不同的方法,来自虚拟主机?

art*_*ung 5

我喜欢:

# force www IN URL
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
# END force www IN URL
Run Code Online (Sandbox Code Playgroud)

基本上任何不是 www.example.com的东西都会被重定向301'd.