अपना SSL certificate install करने के बाद, आपको सारा HTTP traffic HTTPS पर redirect करना होगा। Redirect के बिना, http://yourdomain.com access करने वाले visitors encrypted connection use नहीं करेंगे — भले ही HTTPS available हो।
301 (permanent) redirect use करें ताकि search engines सभी ranking signals HTTPS URL पर transfer करें।
Nginx
Port 80 के लिए एक separate server block add करें जो सब कुछ redirect करे:
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
return 301 https://$host$request_uri;
}
यह full URL path preserve करता है: http://example.com/page?q=1 → https://example.com/page?q=1।
Edit करने के बाद, test करें और reload करें:
sudo nginx -t && sudo systemctl reload nginx
Apache
Option 1: VirtualHost Redirect (Recommended)
अपने Apache config में add करें:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
Redirect permanent / https://example.com/
</VirtualHost>
Option 2: .htaccess (Shared Hosting)
अगर आपके पास VirtualHost config की access नहीं है (shared hosting), तो अपनी site की .htaccess में add करें:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
इसके लिए mod_rewrite enabled होना required है।
Changes के बाद:
sudo apachectl configtest && sudo systemctl reload apache2
Redirect Verify करें
# Should return 301 with Location: https://...
curl -I http://yourdomain.com
Expected output:
HTTP/1.1 301 Moved Permanently
Location: https://yourdomain.com/
HSTS: Double Lock
अपने redirect confirm करने के बाद, HSTS (HTTP Strict Transport Security) add करें। यह browser को बताता है कि हमेशा HTTPS use करें, भले ही user http:// type करे:
Nginx:
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains" always;
Apache:
Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains"
Test करने के लिए छोटे max-age (e.g., 300 seconds) से start करें, फिर जब सब कुछ ठीक काम कर रहा हो तो 2 years (63072000) तक बढ़ाएं।
Warning: एक बार HSTS long
max-ageके साथ active हो जाने पर, browsers HTTP पर connect करने से refuse कर देंगे भले ही आप HTTPS हटा दें। Long duration set करने से पहले ensure करें कि आपका HTTPS setup stable है।
Common Redirect Patterns
www को non-www + HTTPS पर Redirect करें
# Nginx: www → non-www, HTTP + HTTPS → HTTPS
server {
listen 80;
listen 443 ssl;
server_name www.example.com;
ssl_certificate /etc/ssl/fullchain.pem;
ssl_certificate_key /etc/ssl/privkey.pem;
return 301 https://example.com$request_uri;
}
non-www को www + HTTPS पर Redirect करें
server {
listen 80;
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/ssl/fullchain.pem;
ssl_certificate_key /etc/ssl/privkey.pem;
return 301 https://www.example.com$request_uri;
}
पूरा Old Domain Redirect करें
server {
listen 80;
listen 443 ssl;
server_name olddomain.com www.olddomain.com;
ssl_certificate /etc/ssl/old-fullchain.pem;
ssl_certificate_key /etc/ssl/old-privkey.pem;
return 301 https://newdomain.com$request_uri;
}
आपको old domain के लिए भी एक valid SSL certificate चाहिए — browser को redirect receive करने से पहले HTTPS establish करना होगा। दोनों domains को cover करने वाले SAN certificate use करें, या old domain के लिए separate certificate।
Troubleshooting
Redirect Loop (ERR_TOO_MANY_REDIRECTS)
इसका usually मतलब है कि आपका HTTPS server block भी HTTPS पर redirect कर रहा है। Check करें कि सिर्फ port 80 block में redirect है — port 443 block normally content serve करे।
एक और reason: load balancer या proxy (Cloudflare, AWS ALB) SSL terminate करता है और आपके server को HTTP forward करता है। आपका server HTTP देखता है और redirect करता है। X-Forwarded-Proto header check करके fix करें:
# Behind a proxy/load balancer
if ($http_x_forwarded_proto = "http") {
return 301 https://$host$request_uri;
}
पुराने HTTP URLs Search Engines में Cached हैं
Redirect set करने के बाद, Google को change के बारे में बताएं:
<link rel="canonical">कोhttps://पर update करें- अपने sitemap URLs को
https://पर update करें - Google Search Console में, HTTPS property add करें
जैसे-जैसे Google 301 redirects follow करता है, वह gradually indexed URLs update करेगा।
FAQ
क्या मुझे www को non-www (या vice versa) पर same time redirect करना चाहिए?
हां। एक canonical form choose करें और दूसरे को redirect करें। यह search engines में duplicate content से बचाता है:
# Redirect www to non-www (Nginx)
server {
listen 80;
listen 443 ssl;
server_name www.example.com;
return 301 https://example.com$request_uri;
}
क्या redirect SEO को affect करेगा?
301 redirect destination URL को ranking signals pass करता है। Google HTTP-to-HTTPS migration के लिए 301 redirects recommend करता है। थोड़ा, temporary fluctuation हो सकता है, लेकिन HTTPS ranking signal की वजह से long term में SEO improve होता है।
Redirect करने के बाद mixed content का क्या?
Redirect page URL handle करता है, लेकिन अगर आपका HTML resources (images, scripts, CSS) को http:// URLs से reference करता है, तो browsers उन्हें block करेंगे या warning दिखाएंगे। हमारी mixed content fix guide देखें।
मैं कैसे test करूं कि मेरा redirect सही काम कर रहा है?
# Check redirect chain
curl -ILs http://yourdomain.com | grep -E '^HTTP|^Location'
Expected output:
HTTP/1.1 301 Moved Permanently
Location: https://yourdomain.com/
HTTP/2 200
First response HTTPS Location के साथ 301 होना चाहिए, और final response 200 होना चाहिए।
क्या मुझे DNS level पर या server level पर redirect करना चाहिए?
Server level पर (Nginx/Apache config या .htaccess)। DNS-level redirects (जैसे Cloudflare के Page Rules) काम करते हैं लेकिन एक network hop add करते हैं और आपको redirect behavior पर कम control देते हैं। Server-level redirects faster और ज्यादा reliable हैं।