Skip to content

Developer tools

.htaccess Redirect Generator

Create Apache rewrite rules for cPanel and other shared hosts: force HTTPS, choose www or not, and send old URLs to new ones with 301 redirects.

www

        

Back up your current .htaccess first, and paste these rules above any existing rewrite rules.

How to use the .htaccess Redirect Generator

  1. 1

    Tick the rules you need and list old → new URLs, one pair per line.

  2. 2

    Copy the generated block.

  3. 3

    Back up your .htaccess, then paste the block at the top, before other rewrite rules (for Laravel: before its own rules in public/.htaccess).

Frequently asked questions

301 or 302?

301 means "moved permanently": browsers and Google update to the new URL and pass on its ranking. Use 302 only for temporary moves.

My site shows "Too many redirects"

Usually HTTPS is forced twice (by the host or Cloudflare and by .htaccess). The generated rule also checks X-Forwarded-Proto to avoid this behind proxies; remove other HTTPS redirects if it persists.

Does this work on Nginx?

No. .htaccess is Apache (and LiteSpeed, used by many cPanel hosts). Nginx needs rules in its server config instead.

Embed this tool on your site

Paste this code into your page. It's free, with no sign-up, ads or cookies.

Preview

Please keep the "Powered by Dev-Talk" link.

Get new articles in your inbox

Practical tutorials and deep dives, about once a week. No spam, unsubscribe anytime.

Privacy policy

Add DEV Talk to your Home Screen

  1. 1 Tap the Share button in Safari's toolbar.
  2. 2 Scroll down and tap Add to Home Screen.
  3. 3 Tap Add. Open it from the Home Screen to read like an app and to turn on notifications with the bell.

We use cookies to improve your experience and analyze traffic. By continuing, you agree to our Privacy Policy.