How to Set Up Redirects and Rewrite Rules with .htaccess
The .htaccess file is a powerful configuration tool that lets you control how your web server handles requests. On dotCanada's LiteSpeed-powered hosting, .htaccess rules work seamlessly and take effect immediately - no server restart required.
Basic Redirects
Simple redirects can be set up with the Redirect directive:
Redirect 301 /old-page.html https://yourdomain.com/new-page/Use 301 for permanent redirects (passes SEO value) and 302 for temporary ones.
URL Rewriting with mod_rewrite
For dynamic rewrites, enable the rewrite engine and define rules:
RewriteEngine On
RewriteRule ^blog/([0-9]+)/?$ blog.php?id=$1 [L,QSA]This rewrites /blog/42/ to blog.php?id=42 without changing the visible URL.
Redirecting HTTP to HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]Redirecting www to Non-www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com [NC]
RewriteRule ^(.*)$ https://yourdomain.com/$1 [L,R=301]Common .htaccess Flags
[L]- Stop processing rules after this one[R=301]- Redirect with the given status code[NC]- Case-insensitive matching[QSA]- Append query string to rewritten URL
If your rewrite rules aren't working as expected, contact our support team and we'll help you sort it out.
100% Satisfaction Guarantee
We're so confident you'll love dotCanada that we offer a 30-day money-back guarantee. Not satisfied? Get a full refund, no questions asked.
Ready to Get Started?
Join thousands of Canadian website owners who trust dotCanada for reliable, fast web hosting.
Get Started Today
