Hello,

I require the following redirection applying 301 redirection:

Redirected from:

Redirected to:

Kindly assist me how it can be accompalished for all pages.

Thanks in advance!

Dani AI

Generated

A site-wide permanent redirect (301) from the www host to the non‑www host is a canonicalization task best done at the web‑server level so paths and query strings are preserved and search engines treat the non‑www version as canonical. As notes, DNS cannot perform an HTTP redirect. ’s server‑level suggestion is the right direction; avoid client‑side meta refresh for SEO (see ). If hosting control panels are available, is correct that many panels offer a one‑click canonical host option.

Common server examples (preserve path and queries):

Apache (prefer vhost; use .htaccess only on shared hosts)

<VirtualHost *:80>
    ServerName www.example.com
    Redirect 301 / http://example.com/
</VirtualHost>

Nginx (return a permanent redirect)

server {
    listen 80;
    server_name www.example.com;
    return 301 https://example.com$request_uri;
}

IIS web.config (URL Rewrite module)

<rule name="Redirect www to non‑www" stopProcessing="true">
  <match url="(.*)" />
  <conditions>
    <add input="{HTTP_HOST}" pattern="^www\.(.+)$" />
  </conditions>
  <action type="Redirect" url="https://{C:1}/{R:1}" redirectType="Permanent" appendQueryString="true" />
</rule>

Operational notes and checks: ensure both www and non‑www A/AAAA records point to the server (DNS must resolve to allow the redirect). If HTTPS is used, the www name needs a valid certificate (otherwise browsers show a warning before any redirect). Test with a tool such as curl -I -L http://www.example.com/some/path and confirm an HTTP/1.1 301 and the Location header contains the non‑www URL. Finally, remove redirect chains, update internal links, sitemap entries and analytics/Search Console settings so the non‑www host becomes the canonical reference.

Recommended Answers

All 6 Replies

Do you control the DNS?

Unfortuantely, DNS cannot perform an actual redirect.

Kindly assist me how it can be accompalished for all pages.

You need server side scripting, or the rediret can be done at the web server level as well (two websites, one site dedicated for the redirect to the other, not a great solution). Are you running the site with server side (php, asp.net, jsp, etc..) code?

The best and easiest solution is to add a redirection instruction to your .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.hostingwebsitedomain.com$
RewriteRule ^(.*)$  [R=301,L]

Try inserting the following code in your <head> </head> tag:

<meta http-equiv="refresh" content="0; url=http://www.example.com/">

"content" specifies how many seconds elapse before you are forwarded

redirection instruction to your .htaccess file:

... assuming that there is php here..

<meta http-equiv="refresh" content="0; url=http://www.example.com/">

that would work if there were actually two web sites. oh and you'd have to do that for every page.

If the only thing you try to achieve, is to have the www writing of your url to redirect to the non www versiin (aka canonicalizstion of your domain url) then the easiest way is to do it is through the plesk, cpanel etc by setting the desired version in the domain settings. Provided,of course that you have such access.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.