Home » » Cara Redirect Semua Url Domain Lama ke Domain Baru dengan .htaccess

Cara Redirect Semua Url Domain Lama ke Domain Baru dengan .htaccess

Redirecting all URLs from olddomain.com to newdomain.com

Berikut Jika ada case, misalnya punya website dengan domain domain.id di tempat hosting A, kemudian ada rencana untuk pindah dari domain.id ke domain.co.id di hosting baru.


setelah website selesai dibuat di domain dan hosting .co.id, tidak hanya cuku diredirect, kenapa ?
karena domain.id sudah tersebar di pencarian google, jadi apapila ada customer yang mencari produk dia masukknya ke domain.id/url/url nah, dia masih tetap bisa mengakses domain.id kita padahal sudah di redirect ke .co.id dan di website dan domain.id sudah tidak digunakan, akibatnya pastinya kurang efisien kan. karena pengunjung akan beli diwebsite.id yang harusnya sudah tidak kita pakai lagi karena sudah pindah domain.

Untuk itu solusinya menggunakan redirect Semua Url dengan .htaccess, denga redirect .htaccess, semua url yang mengandung domain website.id website lama kita tadi, akan ikut diredirect ke hosting baru yang kita arahkan tadi yaitu .co.id. dengan begitu visitor / customer tidak akan salah beli/bingung ketika mengakses website kita yang ternyata sudah pindah hosting dan domain.

So the example below is redirecting all URLs from olddomain.com to newdomain.com

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.olddomain\.com$
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^olddomain\.com$
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]


You can also apply this to a subdomain – so the example below is redirecting all URLs from subdomain.olddomain.com to subdomain.newdomain.com

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^subdomain.olddomain.com$
RewriteRule ^(.*)$ http://subdomain.newdomain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.subdomain.olddomain.com$
RewriteRule ^(.*)$ http://subdomain.newdomain.com/$1 [R=301,L]


Force a Directory Folder or WebSite to go over HTTPS SSL with htaccess

To force a website to use the secure protocol SSL running the whole site over HTTPS you can make a simple edit to the .htaccess file in the document root.

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
To force a particular folder or directory to serve over SSL, create a .htaccess file in that folder and apply the following to it:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} somefolder
RewriteRule ^(.*)$ https://www.domain.com/somefolder/$1 [R,L]
This assumes SSL is enabled on the domain on an Apache Web Server with the  mod_rewrite module enabled.

Redirecting WWW to non-WWW with htaccess

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Just make sure you add it at the very top of the htaccess file.

Refrensi :
https://coolestguidesontheplanet.com/redirecting-a-web-folder-directory-to-another-in-htaccess/
Share this on your favourite network

0 comments:

Post a Comment

Kibarkan Indonesia melalui Tulisan Inspirasimu ! #AYOMENULIS

Kibarkan Indonesia melalui Tulisan Inspirasimu ! #AYOMENULIS
Sudah waktunya, Indonesia Butuh Lebih Banyak Inspirator, yang bisa menjadikan moral anak muda menjadi lebih tergerak untuk maju, berjuang mengibarkan merah putih lebih tinggi !

Masih Jaman Website Lemot ?

Like us on Facebook
Follow us on Twitter
Recommend us on Google Plus