PLATFORM
  • Tails

    Create websites with TailwindCSS

  • Blocks

    Design blocks for your website

  • Wave

    Start building the next great SAAS

  • Pines

    Alpine & Tailwind UI Library

  • Auth

    Plug'n Play Authentication for Laravel

  • Designer comingsoon

    Create website designs with AI

  • DevBlog comingsoon

    Blog platform for developers

  • Static

    Build a simple static website

  • SaaS Adventure

    21-day program to build a SAAS

Written By
Views

How to make your site redirect with and without the 'www'

Using your .htaccess you can do a lot of things, such as making SE Friendly URL's. One more great trick is the ability to redirect your site so that it always points to the www version or without. Let's say that your base URL for your site is linking all your CSS or JS files from the www version of your site, in that case you would want all your pages to redirect to the www version of your site. for example (www.example.com as opposed to just example.com)

Well it's very simple, to add the www to your site, just enter the following code in your .htaccess file

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

Alternatively, if you wanted to remove the www from your site so that way they always end up at yoursite.com as opposed to www.yoursite.com you would add the following code to the .htaccess:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

And, that's it! Simple enough. ;)

Comments (0)

loading comments