Tools
PDF Tools 34
Image Tools 5
AI Writing 13
Text Tools 13
SEO and websites 22
YouTube and video 13
Calculators and converters 17
Developer Tools 13
Other tools 2
Scanner Blog
Language

.htaccess Redirect Generator

Create Apache rules for HTTPS, www and 301 redirects and caching.

Related tools

All tools in this group
Illustration of options turned into an .htaccess file

Ready-made .htaccess rules without learning Apache

The small .htaccess file at the root of your site controls big things: sending visitors to HTTPS, settling on one address with or without www, the 404 error page and caching. Writing its directives by hand is error-prone, though, and one mistake can take the whole site down. Jood's .htaccess redirect generator writes the most common rules for you, correctly.

How to use it

  1. Under "Choose the rules", tick what you need; you can pick more than one.
  2. Type the "Domain Name", such as example.com. It is required for the www rules and image protection.
  3. Click "Start Now", then copy the code with "Copy Result".

The available rules

  • Force HTTPS: sends every http visit to https with a permanent 301 redirect. The rule recognizes a secure connection even behind Cloudflare or a proxy, so you do not end up in an endless redirect loop.
  • Force or remove www: pick one of the two. Combined with HTTPS, the tool writes a single redirect instead of two in a row.
  • Custom 404 error page: shows the /404.html file for pages that do not exist, so create that file at the site root.
  • File compression and browser caching: turns on gzip compression for text files and asks the browser to keep images for a year, and CSS and JavaScript files for a month.
  • Prevent image hotlinking: stops other sites from showing your images on their pages at the expense of your hosting, while opening an image directly still works.

Before you upload the file

  • .htaccess works on Apache and LiteSpeed servers, which are common on shared hosting with cPanel. Nginx servers ignore it completely.
  • Make a copy of your current file before any change; you may need to put it back within seconds.
  • On WordPress, place the rules before the # BEGIN WordPress line and leave the WordPress block alone.
  • Change the domain name if you move the site, or you will send visitors to the old address.

After uploading, test the http:// version of your site with the HTTP headers checker to see the 301 code and where it points, then confirm that the destination works with the HTTP status code and redirect checker.

FAQ

لا، ملف .htaccess خاص بـ Apache. Nginx يحتاج قواعد في إعداداته.
استعد النسخة الاحتياطية of الملف، ثم أعد إضافة القواعد واحدة واحدة لتعرف أيها السبب.
اختر نسخة واحدة والتزم بها، فتعدد النسخ يشتت الفهرسة. أيهما تختار لا يهم بقدر ثباتك عليه.