Arama Yap Mesaj Submit
Request a Callback
+90
X
X

Select Your Currency

Turkish Lira $ US Dollar Euro
X
X

Select Your Currency

Turkish Lira $ US Dollar Euro

Contact Us

Location Halkali merkez neighborhood fatih st ozgur apt no 46 , Kucukcekmece , Istanbul , 34303 , TR
Canonical Host and Domain Standard

How to Redirect www to non-www?

www and non-www are technically different hosts. One version must be chosen as canonical, and the other must be redirected to the HTTPS canonical target with a single 301. The certificate must cover both hosts, and subdomains must not be accidentally redirected to the main domain with a broad regex.

www Redirectnon-wwwCanonical DomainSSLSubdomain
Apache/LiteSpeed Diagnostics
www.example.com -> example.com
301 Moved Permanently
SSL_ERROR_BAD_CERT_DOMAIN
Redirect loop
Canonical host mismatch
01Verify file and document root
02Take a backup and read the error log
03Separate server and application context
04Verify live result with curl
01
Safe technical approach

Redirecting www and non-www How to analyze?

www and non-www are technically different hosts. One version must be chosen as canonical, and the other must be redirected to the HTTPS canonical target with a single 301. The certificate must cover both hosts, and subdomains must not be accidentally redirected to the main domain with a broad regex.

01

Determine server type

Do not expect a `.htaccess` result without reserving the Apache, LiteSpeed, Plesk proxy or NGINX-only structure.

02

Get backup and logs

Back up the current file with the date; Find the directive and line in the Apache/LiteSpeed error log.

03

Change one rule

Do not change redirect, rewrite, header and access rules all at the same time.

04

Test from outside

Measure the status, Location, Content-Type and redirect number with curl and check the cache layers separately.

Do not use any Host header from the user as a redirect target.

02
Live problem dictionary

Apache, redirect and access messages

01kritik

www redirect loop

Meaning: The www and non-www rules redirect to each other.

Possible cause: Two panel or two `.htaccess` rules.

02kritik

SSL certificate error on www

Meaning: TLS verification fails before the redirect takes place.

Possible cause: Sertifika SAN listesinde www yok.

03warning

Subdomain redirecting to main domain

Meaning: The host condition is too broad.

Possible cause: All `*.example.com` subdomains are matching.

04warning

HTTP www is redirected twice

Meaning: Protocol and host are in separate rules.

Possible cause: HTTPS first, then non-www.

05warning

WordPress is appending www again

Meaning: The Home/Site URL points to a different canonical host.

Possible cause: Application URL setting.

06warning

Plesk preferred domain conflicts

Meaning: The panel and `.htaccess` use different targets.

Possible cause: Two management points.

07warning

Cloudflare Bulk Redirect conflict

Meaning: The edge and origin target different hosts.

Possible cause: Double redirect.

08bilgi

Search Console shows two properties

Meaning: Host variations may be separate URL-prefix properties.

Possible cause: Normal ownership separation.

No records matching this expression were found.

03
Copiable controls

curl, Apache log and file tests

Four host/protocol tests

for u in http://example.com https://example.com http://www.example.com https://www.example.com; do curl -sS -o /dev/null -w "$u -> %{http_code} %{url_effective} redirects:%{num_redirects}\n" -L "$u"; done

Compares all basic URL variations.

Location zinciri

curl -sIL --max-redirs 10 http://www.example.com/path?x=1 | grep -iE '^HTTP|^location:'

Shows the redirect chain with path and query.

Certificate hosts

echo | openssl s_client -connect example.com:443 -servername www.example.com 2>/dev/null | openssl x509 -noout -ext subjectAltName

Shows whether the certificate covers the www and non-www hosts.

Host rules

grep -nE 'HTTP_HOST|SERVER_NAME|www\\.|example\\.com|R=301' .htaccess

Finds the canonical host rules.

DNS records

dig +short example.com A; dig +short www.example.com A; dig +short www.example.com CNAME

Shows the DNS targets for www and the root domain.

Canonical etiketi

curl -sL https://example.com/path | grep -ioE '<link[^>]+rel=["'"']canonical["'"'][^>]*>' | head -n 1

Shows the target page's canonical host.

04
Correct and incorrect structure

.htaccess rule comparisons

www’den non-www

Risky / Incorrect
RewriteCond %{HTTP_HOST} www.example.com
RewriteRule ^ http://example.com%{REQUEST_URI} [R=301,L]
Right Approach
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L]

non-www’den www

Risky / Incorrect
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Right Approach
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L]

Subdomain protection

Risky / Incorrect
RewriteCond %{HTTP_HOST} !^example\.com$
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L]
Right Approach
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L]

Host header security

Risky / Incorrect
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Right Approach
RewriteCond %{HTTP_HOST} ^(?:www\.)?example\.com$ [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L]
05
Application by infrastructure

Apache, cPanel, Plesk, LiteSpeed and applications

Apache / LiteSpeed

The full host condition and final HTTPS target can be managed in a single rule set.

  • Write the canonical host explicitly.
  • Subdomainleri exact regex ile koruyun.
  • Run the rule before the application rewrite.

Cloudflare / CDN

DNS proxy and edge redirect may conflict with origin rules.

  • Check for Bulk Redirect or Redirect Rule.
  • Do not leave duplicate rules on the origin.
  • Verify the SSL certificate on both origin and edge.

WordPress / Plesk / WISECP

The application and panel domain settings must match the chosen host.

  • Match the WordPress Home/Site URL.
  • Verify the Plesk Preferred domain setting.
  • Update the WISECP system URL to the canonical host.
Incorrect interventions

Absolutely don't

  • Do not use any Host header from the user as a redirect target.
  • Do not redirect all subdomains to the main domain with a broad regex.
  • Do not publish an HTTPS www redirect without the certificate covering the www host.
  • Do not define the same operation three times across the panel, CDN, and `.htaccess`.
Post-procedure check

Verify the solution

  • All four basic URL variations reach the single canonical host.
  • The redirect uses a single hop and returns the expected 301 or 308 code.
  • The SSL certificate covers both main hosts.
  • Canonical, sitemap, and app URL settings use the same host.
06
Internal SEO content set

Related .htaccess solutions

07
primary sources

Apache, WordPress and panel documentation

08
Frequently asked questions

Redirecting www and non-www Curiosities about

Does the www and non-www redirect rule work on NGINX?

No. NGINX does not read `.htaccess` files. The rule must be translated to a `server` or `location` configuration.

Is Apache restart required for .htaccess changes?

Usually not; Apache evaluates the `.htaccess` file on each request. However, a reload or restart is required for VirtualHost, module, or AllowOverride changes.

What should be done before editing the file?

A dated backup of the existing file should be taken, the active document root verified, and the change tested on staging or during low-traffic periods.

Where is the file located in Plesk with cPanel?

In cPanel it is usually inside `public_html`, in Plesk inside `httpdocs`; addon domains and subdomains may have a different document root.

Does LiteSpeed support `.htaccess` rules?

LiteSpeed supports most rules through Apache compatibility; some module and handler behaviors may differ.

Where should I look first in case of a 500 error?

Full directive and line record in Apache/LiteSpeed error log. The file should be restored according to the log instead of being deleted randomly.

Can these codes be added directly to the live site?

Domain should not be added directly without verifying domain, document root, proxy, WordPress, and server structure. Examples should be adapted and tested.

EKA SOFTWARE AND INFORMATION SYSTEMS

Let's edit .htaccess and Apache rules without making the site inaccessible

We examine redirection, rewrite, CORS, access and 500 errors with logs in cPanel, Plesk, LiteSpeed, WordPress, custom PHP and WISECP structures.

Get Server SupportWhatsApp
Top