.htaccess generator

The .htaccess generator helps you create ready-made Apache rules without manually entering directives and regular expressions. You specify the source address, destination URL, and desired redirect type, then copy the generated code into your website's configuration file.

The site domain the rules are built for.

seo-gen.com.ua

Settings

Load the list from a file

Load the list from a file

Everything is computed in your browser — not a single line leaves it.

The ready code

The code appears as soon as you fill the fields: it will hold no empty values and no invented placeholders.

The same for nginx

The code appears as soon as you fill the fields: it will hold no empty values and no invented placeholders.

What to do next

Send a requestOur service: website promotion

What is an .htaccess generator and what is it used for?

This online .htaccess generator is useful when moving pages, changing the URL structure, switching to HTTPS, or setting up the primary version of a domain. Before adding rules, save a backup copy of the current file and be sure to check the actual HTTP response code after making changes.

The .htaccess file stores local Apache web server settings for the website directory and its subsections. It is used to configure URL redirection, rewrite rules, error handling, access restrictions, and other parameters allowed by the server configuration.

.htaccess generator reduces the amount of manual work with Apache mod_rewrite syntax and helps avoid simple errors in RewriteRule or RewriteCond. In English-language documentation and services for this tool, you'll also find search terms like "htaccess generator" and "apache htaccess generator".

What tasks does the .htaccess generator solve?

The generator is most often used for changing page addresses and technical URL normalization. It helps prepare rules for permanent and temporary redirects, protocol changes, primary domain versions, and other common Apache scenarios.

The main tasks can be reduced to several groups:

  • redirecting an old URL to a new address after changing the site structure;
  • creating 301 or 302 redirects for individual pages and sections;
  • translation of requests from HTTP to HTTPS without unnecessary intermediate transitions;
  • Setting up www and non-www domain versions;
  • transferring pages or the entire project to another domain;
  • removing index.php or index.html from the page address;
  • working with trailing slash and a unified URL format;
  • Preparing RewriteRule and RewriteCond for Apache.

After generating the rule, you still need to test it on the live server. The site configuration may contain old RewriteRules, CMS settings, or server restrictions that will affect how the new code is processed.

What servers is the generator suitable for?

The .htaccess syntax applies primarily to the Apache web server, where directives can be applied at the directory level. Therefore, the Apache redirect generator generates rules specifically with Apache logic and the mod_rewrite module in mind.

LiteSpeed supports a significant portion of Apache syntax, so many rules work on these servers without modification. Nginx uses a different configuration format, so .htaccess code can't be directly migrated without modifying the directives.

Before deployment, check the web server type in your hosting panel, technical documentation, or response headers. This is especially important when using a VPS, CDN, or proxy server, where the actual request processing scheme may differ from the standard Apache.

How to use the .htaccess generator?

Working with the generator begins with defining the task: which URL should receive the request and where the user or search robot should go. Then, a permanent or temporary redirect is selected and additional parameters are specified, if necessary for the current scenario.

The htaccess redirect generator creates a ready-made structure that can be inserted into an existing file. Before saving changes, it's recommended to open several test URLs and determine the expected destination address for each one.

Specify the source and destination URLs

The source URL is the address the user or search engine currently requests. The target URL is the page the redirect should point to after the rule is processed by the server. For example, the old catalog /catalog-old/ could be redirected to the new address /catalog/.

During a mass migration, old and new URLs must be matched pairwise to ensure each source URL corresponds to the correct destination URL. An error in this list can send traffic to an irrelevant page and disrupt the site's internal structure.

If you're using the htaccess redirect generator for a large number of pages, first test a few lines manually. Then, test a random selection of URLs from the beginning, middle, and end of the list.

Select the redirect type

For a permanent address change, the 301 Moved Permanently code is typically used. This is suitable for moving a page, merging duplicates, changing the URL structure, or migrating a project to a new domain.

Code 302 is used when the redirect is temporary and the original address is intended to be used. The choice between 301 and 302 should depend on the actual task, not on ease of setup.

The htaccess 301 generator is primarily needed for permanent changes. If the change is temporary, you should select the appropriate status and separately check what code the server actually returns after implementing the rule.

Set up additional rules

Additional parameters help align the site to a unified technical version. Depending on the service's features, you can configure HTTP to HTTPS, www or non-www, trailing slashes, domain transfers, and other address normalization options.

Avoid enabling multiple rules with the same purpose. For example, separate conditions for HTTPS and www can create a traffic chain if they are placed in the wrong order or duplicate an existing CMS configuration.

Before generating URLs, determine the final URL format for all site pages. This approach helps immediately route requests to the primary protocol, domain, and path format without any additional intermediate responses.

Generate and copy the code

After filling in the parameters, the service generates a ready-made Apache configuration fragment. Check the source and destination URLs, response code, and RewriteCond conditions, then copy the rule to the .htaccess file.

Don't replace the entire existing file with a new fragment if the generator only creates a single rule. On a production site, .htaccess may contain CMS settings, security, caching, PHP processing, and other directives.

After saving, open the URL you're checking in your browser and additionally check the server status using the redirect checking tool. A visual redirect to a new page isn't enough for a complete technical check.

What rules can be created in .htaccess?

In .htaccess, you can set up specific and wildcard redirects, URL structure modification rules, and request processing conditions. For SEO, 301 redirects, consistent protocol and domain versions, and duplicate URL removal are most often required.

The htaccess rewrite generator is useful where a simple direct redirect isn't enough. RewriteCond specifies the execution condition, and RewriteRule determines which request should be modified and what address the user should receive after processing.

01

301 redirect from old URL to new URL

A permanent 301 redirect is used when the old address should no longer remain the primary page. Typical cases include URL changes, merging duplicates, moving a category, updating the site structure, or migrating to a different domain.

htaccess 301 generator creates a rule that informs browsers and search engines about a permanent address change. Once implemented, the old URL should immediately point to the relevant end page and return the correct status.

Don't redirect a large number of different deleted pages to the homepage just to preserve traffic. For each old URL, it's best to choose the page that's closest in content or leave a proper 404 or 410 response when a suitable replacement isn't available.

Single page redirect

A specific redirect is needed when the address of a single publication, service, category, or other document changes. For example, the page /old-service/ can be moved to /services/new-service/ if the new page actually continues its content.

For this scenario, a single rule matching the old and new URLs is sufficient. Once implemented, verify that the request doesn't go through additional URLs and immediately receives the desired final response.

Pinpoint rules are convenient to test before a mass migration. If the logic works correctly on a few individual pages, the likelihood of errors when expanding the redirect map becomes significantly lower.

Bulk 301 redirects

Mass redirects are used when changing a large number of URLs following a redesign, migration to a different CMS, or restructuring of the catalog. For each old page, the final URL must be determined in advance and accidental matching must be eliminated.

If the interface supports batch mode, the original and new URLs are typically added as two synchronous lists. The number of lines must match, and each pair must correspond to a specific page.

After generation, don't limit yourself to checking the first few lines. Test different page types, ensure there are no chains, and save the map for future indexing monitoring.

02

302 temporary redirect

The 302 code is used for temporary redirects when the original URL should remain the primary working point after the temporary scenario ends. This could be for a short-term page replacement, testing, or a time-limited technical situation.

This response shouldn't be automatically chosen over a 301 simply because it's perceived as a safer option. The status should reflect the actual nature of the change and the expected duration of the redirect.

Once the temporary task is completed, the rule should be removed or permanently updated if the new URL becomes the primary one. Old 302 rules left in place for years complicate the site's technical picture and subsequent audits.

03

RewriteRule and RewriteCond in Apache

Apache mod_rewrite processes requests based on specified conditions and patterns. RewriteEngine On enables the rewrite engine, RewriteCond specifies an additional condition, and RewriteRule defines the rule for modifying or redirecting URLs.

This scheme is necessary when a rule must take into account a domain, protocol, part of the path, URL parameters, or regular expressions. An error in the template can affect more pages than intended, so the conditions must be checked especially carefully.

The Apache htaccess generator typically creates ready-made RewriteCond and RewriteRule constructs for common scenarios. For non-standard logic, the code should be verified against the actual request structure on the site.

When is a Rewrite Rule Generator needed?

The rewrite rule generator is useful when a redirect needs to work not for a single address, but for a group of URLs with a common structure. For example, a rule might take into account a directory, a portion of the path, a protocol, or a specific incoming request pattern.

Regular expressions help reduce dozens of similar strings to a single condition, but they also increase the risk of overly broad matches. Before implementing such a rule, you should test several suitable and several inappropriate URLs.

The htaccess rewrite generator is especially useful when migrating sections with a predictable structure. If the mapping between old and new addresses is chaotic, it's safer to use a precise redirect map without complex regular expressions.

04

Redirect from HTTP to HTTPS

After installing an SSL certificate, it's best to redirect all requests to the HTTP version of the site directly to the corresponding HTTPS address. Both the user and search engine crawler should be directed to the final, secure version without an unnecessary chain of intermediate redirects.

When setting up, check whether your CDN, hosting panel, CMS, or proxy server is performing a similar redirect. Duplicate rules can sometimes cause a redirect loop or create additional responses between the source and destination URLs.

After changing the rule, test the main page, internal URLs, and URLs with parameters. A valid rule should preserve the desired path and not send all requests to a single, common URL.

05

Redirect from www to non-www and back

For a single website, choose a primary domain version and use it consistently in internal links, canonicals, sitemaps, and server redirects. The www.example.com and example.com versions should not be opened as independent copies of pages.

The rule can direct www to a non-www domain or perform a reverse redirect. The choice depends on the current architecture, the historical version of the site, and the accepted address standard.

When combining such a rule with HTTPS, it's best to create a single transition directly to the final version. For example, a request for http://www.example.com/page/ should preferably be routed directly to the selected HTTPS version of the page.

06

Redirect to another domain

When changing a domain, it's important to maintain consistency between the old and new pages so users are directed to relevant content. Simply redirecting all URLs to the new site's homepage usually degrades the migration experience.

If the structure of two sites is identical, you can use a template rule to transfer the path. If the architecture has changed, it's more reliable to prepare a separate map of the old and new URLs and test it before launching.

After the move, monitor the status of the old pages, final URLs, canonicals, internal links, and indexing. The old domain should continue to respond correctly long enough for search engines to process the move.

07

Removing index.php, index.html and URL normalization

A single document is sometimes accessible at multiple URLs, such as /, /index.php, and /index.html. If a server serves the same content at different URLs, this creates unnecessary crawling options and potential duplicates for search engines.

A redirection rule can force such URLs to a single primary version. Similar logic applies to trailing slashes, character case, and other technical differences in URL structure.

Normalization must be coordinated with canonical URLs, sitemaps, and internal linking. Server redirects correct incoming requests, but the site's internal links should also point directly to the main URL.

What we actually did

Dental clinic · Kyiv and Chernihiv

+44% clicks from search

A domain with no history on a website builder. We built the semantic core for both cities, reworked the landing pages and built the link profile from zero. Four months: 34.8k clicks, impressions 1.32 → 1.76M, DR 0 → 41.

E-commerce · international

+96% clicks in two months

A catalog of digital 3D models. We clustered the semantics, rebuilt the hub pages and closed duplicates and indexing errors. Google users 247 → 532, CTR 2.4% → 4%.

Medical center · Ukraine

+68.75% visibility in the first month

Narrow visibility and a small semantic core at the start. Semantics, landing page structure, metadata and internal linking, then gradual link building.

Answers to your questions

What is an .htaccess file?

.htaccess is an Apache configuration file that can control the behavior of requests within a specific website directory. It specifies redirects, RewriteRules, access restrictions, error handling, and other server-allowed directives.

The file is applied without restarting the entire server, so it's often used on regular shared hosting. However, the available commands depend on the Apache configuration and permissions set by the hosting provider.

Before editing, save a backup copy of the current version. A syntax error can affect the entire site or the individual directory where the file is located.

Is it possible to create a 301 redirect using .htaccess?

Yes, Apache supports permanent redirects via .htaccess, including dotted and wildcard rules. For a simple URL change, you can create a direct 301, while RewriteCond and RewriteRule are used for more complex logic.

The htaccess 301 generator simplifies the preparation of such code and helps you get the basic structure down quickly. After pasting, be sure to verify that the old URL returns a 301 and immediately leads to the correct destination page.

For mass migrations, additionally check the consistency of each URL pair. An error in the redirect map affects not only the user but also how search engines process old URLs.

What is the difference between 301 and 302 redirects?

301 is intended for permanent relocations, where a new URL should replace the old one. 302 is used for temporary relocations, after which the original page can become the primary entry point again.

This distinction is important during site migrations, restructuring, and maintenance. The status should reflect the expected timeframe for the change, not be chosen randomly based on similar browser behavior.

After configuration, always check the actual HTTP response. 301 and 302 may appear identical because the user is automatically redirected to a different URL in both cases.

How to redirect HTTP to HTTPS using .htaccess?

For Apache, you can use a condition that detects an unencrypted request and sends it to the corresponding HTTPS address. In a typical configuration, this is accomplished via RewriteCond and RewriteRule.

Before adding a rule, make sure HTTPS is already enabled, the certificate is valid, and that a similar redirect isn't running at another level. Otherwise, you may end up with an extra chain or loop.

After implementation, check your internal pages, URL parameters, and the selected www version. A good setup routes the initial request directly to the final primary HTTPS address.

How to redirect from www to a non-www domain?

You need to select a non-www domain as the primary version and configure a server rule for all requests to the www version. A similar scheme works in reverse if a www domain is selected as the primary version.

The redirect should be coordinated with the canonical, sitemap, and internal links so that the site uses the same version everywhere. This reduces technical duplication and simplifies URL processing for search engines.

When switching to HTTPS simultaneously, combine the conditions so that the request doesn't pass through multiple intermediate addresses. After configuration, test all protocol and domain combinations.

Where is the .htaccess file located on a website?

On many hosting providers, the main .htaccess file is located in the website root, for example, in the public_html directory. This file is usually hidden, so the file manager should show system and hidden elements.

In some projects, additional .htaccess files may be located in nested directories and apply only to the corresponding part of the site. Therefore, when searching for conflicts, it's important to consider more than one root file.

If the server runs Nginx without Apache, this file may not exist at all. In this case, the rules are configured in the server configuration rather than created within the site directory.

Why do I get a 500 error after changing .htaccess?

Most often, the cause is a syntax error, an unsupported directive, or a conflict with existing rules. The server cannot correctly process the configuration and returns a generic 500 response.

First, restore a working copy of the file, then add new lines in small chunks. The Apache error log usually contains a more precise message and can help you quickly find the problematic directive.

Don't continue editing dozens of lines simultaneously after an error occurs. The smaller the scope of the last change, the easier it is to determine the cause and safely restore a working configuration.

Is .htaccess generator suitable for Nginx?

No, the standard .htaccess generator creates rules for Apache and compatible syntax. Nginx uses its own directives and doesn't read .htaccess when processing requests.

If you need an Apache redirect generator, the resulting code can be used with Apache after verifying the configuration. For Nginx, the same tasks will need to be implemented using its own return and rewrite rules and server blocks.

Before using the generator, check the actual web server of your project. This will prevent technically correct Apache code from being added to a site where it doesn't run.

The .htaccess generator helps you quickly create Apache rules for 301 and 302 redirects, RewriteRules, HTTPS, primary domain versions, and other common tasks. Before implementing the code, save the working file, check the rule order, and ensure each test URL returns the expected HTTP status.

Specify the source and destination URLs, select the desired redirect type, and create the rule. After copying it to .htaccess, test the final URL, chains, loops, and site functionality across multiple page types.

We reply within one business day. No newsletters, no “just a reminder” calls.

Gennadii, Lead SEO Specialist, Seo-Gen
He will look at the site himself instead of passing it to a manager.
Who will answer: Gennadii
Lead SEO Specialist, Seo-Gen

More on: .htaccess generator

How do I add generated rules to the .htaccess file?

Before editing, find the current file and save a copy separately. Even a small error in Apache syntax can result in a 500 Internal Server Error, so it's important to have a working configuration on hand for quick recovery.

Add new rules in small blocks and test the site after each significant change. This approach makes it easier to find conflicts and helps you understand which condition is causing the error.

Make a backup copy of the current file

Download the current .htaccess file via FTP, your hosting file manager, or your project deployment system. This copy should remain in working order until you add new RewriteRule and other directives.

Don't store a single backup copy in the same file under a random name if the server might handle it in a non-standard way. It's safer to store the file locally or in a version control system.

If the site stops responding correctly after making a change, first restore the previous version. Then add new rules one by one, checking the Apache server error log after each step.

Where is the .htaccess file located?

On regular shared hosting, .htaccess is often located in the website's root directory, for example, public_html/.htaccess. However, the actual path depends on the account structure, domain settings, and server configuration.

A file may be hidden, so sometimes you need to enable the display of hidden files in the file manager. In projects with multiple directories, additional .htaccess files can also be located in subfolders and affect only the corresponding sections.

If the file doesn't exist, don't blindly create it without checking your server configuration. Some hosting providers prohibit certain directives or use a different web server that doesn't process .htaccess at all.

Where to insert new RewriteRules?

The order of rules within .htaccess affects the result because Apache processes conditions sequentially. A more general rule placed above a specific rule can intercept the request earlier and route it differently.

In WordPress and other CMSs, custom redirects are often placed before the system's automatically managed block. However, you shouldn't edit the CMS's internal block if it's overwritten by a settings update.

After pasting, save the file and test several URL types. If the site uses a CDN, server-side cache, or proxy, clear the appropriate cache levels before finalizing the result.

How to check a redirect after changing .htaccess?

After saving the .htaccess file, you should check not only the final page but the entire request path. The browser can quickly perform several transitions in a row, so a visually correct result can sometimes mask a chain or incorrect server status.

To check, use a tool that displays every HTTP response code and next-hop address. This monitoring is especially necessary after a mass migration or simultaneous configuration of HTTPS and the primary domain version.

Check the HTTP response code

For a permanent move, the old URL must return a 301 Moved Permanently response and specify the correct final URL. If the server responds with a 200 response to the old page or uses a JavaScript transition, the purpose of the server-side 301 redirect is effectively incomplete.

In a temporary scenario, the selected 302 status code or another appropriate temporary status should be returned. Verify the response using an external service or developer tools, not just the page content.

For a large list of URLs, it's useful to automate checking and compare actual statuses with a redirect map. This makes it easier to spot missed URLs, 404 errors, and unexpected intermediate transitions.

Check redirect chains

A chain occurs when the source URL first points to an intermediate address and only then to the final page. For example, the path A → B → C creates an additional request compared to a direct path A → C.

Most often, such chains appear after several migrations, when new rules are added over old ones without reviewing the previous configuration. They also occur when HTTP, www, and trailing slash redirects are separate.

If you detect a chain, update the original rule to directly specify the final URL. After making the change, recheck both the old URL and the intermediate pages.

Check for cyclic redirects

A redirect loop occurs when rules send a request in a closed loop, for example A → B → A. In this situation, the browser stops loading after several repeated transitions and displays a redirect error.

This is often caused by conflicting conditions for HTTPS, www, or two separate RewriteRules. Sometimes one rule is in .htaccess, and the other is set in the hosting panel, CMS, or CDN.

To troubleshoot the issue, temporarily disable the latest changes one by one and view the full response path. After fixing the issue, check several similar URLs to ensure the loop is resolved for the entire group of pages.

Clear your cache

After redirects change, the old result is sometimes retained in the browser, CDN, or server cache. Browsers can be particularly proactive in remembering persistent redirects, so simply refreshing the page may not be enough.

Check the URL in a private window, using an external service, or using a command line request that displays HTTP headers without affecting the local cache. If you use a CDN, clear its cache according to your project settings.

The CMS cache can also affect routing if some redirects are generated by the application. After clearing, recheck the source and destination URLs, recording the actual response codes.

What is the difference between 301 and 302 redirects?

301 indicates a permanent resource move and is used when the old URL should no longer remain the primary page. 302 indicates a temporary route change and is suitable for situations where the original URL is planned to be restored to its normal mode.

For SEO purposes, the status selection should be tailored to the actual task. A permanent page migration shouldn't be left in a temporary code for years, and a temporary replacement shouldn't be unnecessarily processed as a permanent move.

CodeRedirect typeWhen to use
301ConstantChanging URLs, moving pages, transferring domains, merging duplicates
302TemporaryShort-term page replacement or temporary route change

After configuration, check the code with a technical tool. The button name or the selected parameter in the generator does not guarantee the final response if existing server rules intercept the request earlier.

Status selection schedule:

URL changes constantly → 301 → check final URL → check for missing chain

URL changes temporarily → 302 → check expiration date → delete rule after completion

This order helps to link the status to the actual task and not leave time settings uncontrolled.

How do .htaccess redirects affect SEO?

Server redirects help search engines understand where a document has moved and which URL should be used next. This is especially important during structure migrations, domain changes, switching to HTTPS, and eliminating technical duplicates.

An incorrect redirect map can direct the robot to irrelevant pages, create chains, or leave some old URLs without a proper response. Therefore, SEO testing is performed after generating rules, rather than ending with copying the code.

Preserving old URL signals

When a URL changes permanently, a 301 redirect links the old URL to the new page and helps search engines process the change. For this to work, the destination page must match the purpose of the old document, and the transition itself must function reliably.

If an old product links to a random category, and a deleted article is relegated to the homepage, the code may technically be correct, but the migration logic will remain weak. The relevance of the final URL must be determined before creating rules.

Eliminating duplicate URLs

A single document can be opened randomly via HTTP and HTTPS, with or without www, with or without /index.php. If these variants return a 200 and are crawlable, the search engine receives multiple URLs with the same content.

A server redirect helps direct requests to the selected version, but it must be aligned with the canonical tag, sitemap, and internal links. It's best to direct all internal website elements directly to the main URL without any intermediate redirects.

After making changes, test multiple page templates, not just the homepage. Categories, articles, products, and URLs with parameters may be processed by different rules or applications.

Why should you avoid redirect chains?

Each additional transition increases the number of server requests and complicates site crawling. Chains often accumulate after several redesigns, when the old address leads to an intermediate URL, which then redirects further.

During the next migration, it's a good idea to rebuild the redirect map so that historical URLs immediately point to the current destination pages. This simplifies technical support and reduces unnecessary transitions.

Be especially careful when checking URL chains on pages with external links and stable search traffic. Such URLs often exist for years and pass through several generations of the site structure.

Is it safe to use generated .htaccess?

The generator reduces the likelihood of manual typos, but the resulting rule operates within a specific server configuration. Existing RewriteRules, CMS settings, Apache version, and allowed directives may alter the expected behavior.

Therefore, it's worth testing the generated code first on several URLs, and for major changes, in a test environment. Keep a working version of the file and don't combine dozens of new rules into a single change without intermediate verification.

What to do if error 500 occurs?

A 500 Internal Server Error after changing .htaccess often indicates a syntax error, an unsupported directive, or a rule conflict. In this case, first revert to the latest working copy and ensure the site is responding normally again.

Next, check the changes step by step:

  1. Restore a working backup copy of the file and open the site again;
  2. add the last rule separately from the rest of the new changes;
  3. check RewriteCond, RewriteRule, flags and special characters;
  4. Open the Apache error log and find the message associated with the request;
  5. Repeat the check after each correction, without returning the entire problematic block at once.

After fixing the error, test more than just the page where you noticed the issue. The template rule may affect other URLs, so you should check the home page, sections, and several internal documents.

Do .htaccess rules work on Nginx?

Nginx doesn't use .htaccess and doesn't read Apache RewriteRule directly. For Nginx, redirects and URL processing rules are defined in server configuration files using a different syntax.

If the project runs on Nginx, the generated Apache code must be converted to the appropriate return, rewrite, or other Nginx settings. Simply copying .htaccess to the site directory will not work.

In a mixed architecture, Nginx can act as a proxy in front of Apache. In this case, it's important to understand at what level a specific request is processed and where exactly the redirect should be placed.