Redirect 301 www.www.example.com

I am using a LAMP server and I need to redirect requests, for example:

www.www.example.com to www.example.com and other options such as (wwww.example.com, etc.)

I know I can do this in .htaccess, but I don’t know the regular expression that I have to use to represent all of these features.

Or is there any other approach coming from vhosts?

+4
source share
3 answers

I like:

# 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 

In principle, everything that cannot be redirected to www.example.com 301.d.

+5
source

See this article for the implementation of "wildcard subdomains." You will need to implement both .htaccess and the Vhosts modification.

http://www.easymodrewrite.com/example-subdomains

If you want to limit it to only "www.www", "wwww." and the other examples above, you can easily do this with some server-side code (which makes it more flexible than embedding more .htaccess). Just determine what a subdomain is and redirect to wherever you want.

+2
source

Using name-based virtual hosts in Apache, you can do this:

 <VirtualHost *:80> ServerName example.com ServerAlias wwww.example.com www.www.example.com [space seperated list] Redirect / http://www.example.com/ </VirtualHost> 

The redirect can take a parameter to indicate the type of redirection.

0
source

Source: https://habr.com/ru/post/1286636/


All Articles