webserver – website only shows with www. before domain


Your privacy


By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.




A Backup software to take snapshot of the www on WHM

Do any of you know any APP or software that can take automatically like every month a Snapshot of the www and selected databases?

Let say… | Read the rest of https://www.webhostingtalk.com/showthread.php?t=1844386&goto=newpost

8 – Redirect domainname from non-www to www in settings.php in combination with https

Because the .htaccess gets overwritten when you update your Drupal Core, I found an other way to implement redirection to https. In settings.php. But below function does not redirect non-www to www.
I would like to extend this function so all domains without www are redirected to www.domain.com.

Below function was found on: https://www.drupal.org/https-information

if ( (!array_key_exists('HTTPS', $_SERVER)) && (PHP_SAPI !== 'cli') ) {
  if (substr($_SERVER('HTTP_HOST'), 0, 4) <> 'www.') {
    $new_url = 'www.' . $_SERVER('HTTP_HOST');
  } else {
    $new_url = $_SERVER('HTTP_HOST');
  }
  $new_url .= $_SERVER('REQUEST_URI');

  header('HTTP/1.1 301 Moved Permanently');
  header('Location: https://'. $new_url);
  exit();
}

With above function:

http://www.mydomain.com redirect to https://www.mydomain.com ==> OK

http://mydomain.com redirect to https://mydomain.com ==> Not OK

I want:

http://mydomain.com or https://mydomain.com to https://www.mydomain.com

Hope this helps.

Will changing a site from no-www to using www affect SEO?

My client wants to switch their site from https://example.com to https:///www.example.com. I know how to make the switch to having www in front of the domain – but does anyone know if making this switch will affect Google Rankings?

http request – Redirect non-www to www in settings.php for Drupal 8

I want to redirect all non-www to www in below function.

if ( (!array_key_exists('HTTPS', $_SERVER)) && (PHP_SAPI !== 'cli') ) {
  if (substr($_SERVER('HTTP_HOST'), 0, 4) <> 'www.') {
    $new_url = 'www.' . $_SERVER('HTTP_HOST');
  } else {
    $new_url = $_SERVER('HTTP_HOST');
  }
  $new_url .= $_SERVER('REQUEST_URI');

  header('HTTP/1.1 301 Moved Permanently');
  header('Location: https://'. $new_url);
  exit();
}

When the site changes to use `www` does the XML sitemap need to be resubmitted via Google Search Console?

You actually need to re-authenticate your new www site. www is a subdomain, and unless your registered a domain with all it’s subdomains to Google Search Console, you need to register every subdomain. Since you need open a new asset in Google Search Console, you will also need to resubmit your sitemap.xml

domains – Making WWW. work for subdomain with no hosting?

We have a domain, example.com for instance. In our DNS settings for this domain, we’ve created a forward for give.example.com subdomain to redirect to another website which works great. (It’s basically just an A record with “give” as the host and the IP of the site we’re redirecting to as the value).

However, if you try www.give.example.com, it does not work. I’ve read that you can add a CNAME record to remedy this but I can’t figure out exactly what I need to add.

apache – Can I use the .htaccess file or another solution to address www and non-www duplicate content issues?

What is “duplicate content”?

“Duplicate content” is simply where you have two or more different URLs referencing essentially the same resource and are not canonicalising this in some way (eg. with a rel="canonical" element or external redirect). https://example.com/foo/bar and https://www.example.com/foo/bar are two different URLs and are consequently treated differently when setting cookies, client-side caches and search engines. Whilst these two URLs might return the same content on your site (and indeed most sites), technically they might not, so do need to be treated differently.

In terms of SEO, search engines might end up (unnecessarily) dividing crawl budget between the two URL versions. They might choose to favour the non-canonical (ie. non-preferred) URL over the other when returning results in the SERPs. You may get backlinks to both URLs which will potentially divide so called “link juice” between the URLs which could result in neither page ranking as well as if you only have one canonical URL for one resource.

Having said that, search engines can often resolve www vs non-www duplicate content issues themselves, providing there is a strong enough signal. But they can still get it wrong.


Resolving “duplicate content”

You can potentially get a duplicate content issue if you are inconsistently linking (or referencing) both example.com and www.example.com throughout your site.

  • If you are using absolute URLs in your internal links then you need to consistently link to www or non-www. OR, use root-relative URLs starting with a slash and omit the scheme and hostname entirely.
  • rel="canonical" link element in the head section of your HTML needs to reference the canonical hostname.
  • XML sitemap needs to reference the canonical hostname.
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 (R,L)

From this HTTP to HTTPS redirect, I assume your canonical hostname uses the www subdomain? If www is not your canonical hostname then that’s obviously an error and should be fixed.

(If you have tested that this is working as expected then this should be a 301 – permanent – redirect, as opposed to a 302 – temporary – redirect, which is what this is currently defaulting to. ie. Change R to R=301 in the RewriteRule flags argument.)

Once you have confirmed/fixed the steps mentioned above then you can implement a non-www to www 301 external “redirect” in your .htaccess file to resolve any URLs that might have been indexed on the non-canonical hostname.

UPDATE: The redirect ensures that only the canonical URL (the www variant in this case) is viewed by users and crawled by search engine bots.

For example, after the HTTP to HTTPS redirect above:

# Redirect example.com to www.example.com
RewriteCond %{HTTP_HOST} ^example.com (NC)
RewriteRule (.*) https://www.example.com/$1 (R=301,L)

TIP: Always test first with 302 (temporary) redirects to avoid potential caching issues, since 301s are cached persistently by the browser.

301 redirect – HAProxy 301 Re-Direct non www to www for root domain

I am trying to setup HAProxy in a way that when a user goes to domain1.com, they are 301’ed to www.domain1.com, while keeping intact the users ability to go to sub1.domain1.com, sub2.domain1.com, etc, the rule I have been trying to use on the front end is:

http-request redirect code 301 location www.domain1.com if {hdr_beg(host) -i domain1.com}

but when I run sudo haproxy -f /etc/haproxy/haproxy.cfg -c to validate of my cfg file, I get the output: error detected in frontend 'https-in' while parsing 'http-request redirect' rule : error in condition: no such ACL : '{hdr_beg(host)'.

Nginx Configuration for support of domain name without “www”

I have deployed a LEMP stack to Linode and purchased a Wildcard SSL Certificate.

Prior to installing the SSL Certificate, I could type in example.com.au OR www.example.com.au and it would bring up the same HTTP website.

After installing the SSL Certificate, I only successfully reach the website when I type in www.example.com.au

I’ve tried setting the server_name inside of the server blocks in the nginx configuration, however, it doesn’t seem to have any effect on it.

Here is my nginx configuration file.

Note – I’m deploying WordPress using docker

upstream php {
    #server unix:/tmp/php-cgi.socket;
    server php:9000;
}

server {
    listen 80;
    listen (::):80;
    server_name *.example.com.au;
    return 301 https://$host$request_uri;
}

server {
    listen 80;
    listen (::):80;
    server_name example.com.au; # <-- this doesnt help at all
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    server_name *.example.com.au;

    ssl_certificate /etc/nginx/certs/bundle.crt;
    ssl_certificate_key /etc/nginx/certs/example.com.au.key;

    root /var/www/html;

    index index.php;

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ .php$ {
        include fastcgi.conf;
        fastcgi_intercept_errors on;
        fastcgi_pass php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~* .(js|css|png|jpg|jpeg|gif|ico)$ {
        expires max;
        log_not_found off;
    }
}

Does anyone have a solution? When I look at the request details in the network tab, I don’t see a “Host” header being sent when typing example.com.au in the URL bar of the browser… but it is present when I type in www.example.com.au

Thanks