β†ͺ️

Htaccess & Nginx Redirect Rule Builder

Generate optimised .htaccess or nginx server configuration syntax for 301 and 302 URL redirects. Handles exact paths, wildcards, and query string preservation.

Redirect Rule Builder

.htaccess

How to use the Redirect Rule Builder

You are migrating your blog from /blog/old-post to /articles/new-post and need visitors and search engines to find the new URL automatically. Enter /blog/old-post in the Source URL field and /articles/new-post in the Destination field. Select 301 Permanent from the dropdown. The tool generates the exact .htaccess or Nginx config line. Click Copy, paste it into your server config, and test with curl -I to verify the 301 response.

Site migration redirects

When restructuring URLs or migrating to a new domain, generate bulk 301 redirects to preserve SEO link equity. For a blog with 50 posts, create 50 individual redirect rules, or use a single wildcard pattern like /blog/(.*) to redirect all posts at once. Each rule generates in under a second.

Apache to Nginx conversion

Switching from Apache to Nginx? Enter the same source and destination, then toggle between .htaccess and Nginx to see both syntaxes. The Apache rule uses RewriteEngine and RewriteRule with flag parameters; the Nginx rule uses a location block with a return directive. Both achieve the same redirect but in completely different syntax.

Campaign URL management

Create temporary 302 redirects for marketing campaigns, A/B tests, or maintenance pages. A 302 tells search engines to keep the original URL indexed while the campaign runs. When the campaign ends, delete the redirect rule -- the original URL retains its ranking because search engines never stopped indexing it.

301 vs 302 redirects and config syntax

The tool generates redirect rules for two server environments: Apache (using .htaccess files with mod_rewrite) and Nginx (using location blocks in server config). Both support exact path matching and regex pattern matching with capture groups.

301 Permanent redirect

Tells browsers and search engines the page has moved permanently. Search engines transfer approximately 99% of link equity to the new URL and update their index within days to weeks. Use for site migrations, URL restructures, and domain changes. The browser caches 301 redirects aggressively, so test carefully before deploying.

302 and 307 Temporary redirects

302 tells search engines the page has temporarily moved and they should keep the original URL indexed. 307 is the HTTP/1.1 equivalent that preserves the request method (POST stays POST). Use 302 for A/B tests and maintenance pages. Use 307 when you need to guarantee the browser does not convert a POST to a GET on redirect.

Apache .htaccess syntax

Rules use RewriteEngine On followed by RewriteRule with a source pattern, destination, and flags. The [R=301,L] flag means permanent redirect and last rule. [QSA] appends query strings. Regex patterns use standard PCRE syntax. Rules are processed in order, so place specific rules before catch-all patterns.

Nginx location syntax

Exact matches use location = /path { return 301 destination; }. Regex patterns use location ~ ^pattern$ { return 301 destination; }. Nginx rules go inside the server block in /etc/nginx/sites-available/ or /etc/nginx/conf.d/. Run nginx -t to test syntax before reloading.

Frequently asked questions

Where do I put the .htaccess redirect rules?

Place them in your site root .htaccess file (the same directory as your index.html or WordPress wp-config.php). Rules are processed in order from top to bottom, so place specific redirect rules before any catch-all or rewrite rules. If your site already has a RewriteEngine On line, do not add a second one -- just add the RewriteRule lines after the existing block.

Will a 301 redirect hurt my SEO?

A properly implemented 301 preserves approximately 99% of link equity according to Google. Search engines update their index within days to weeks. The main risk is redirect chains -- if /old redirects to /intermediate which redirects to /new, equity is lost at each hop. Always redirect directly to the final destination in a single hop.

How do I redirect an entire domain?

For Apache, use a RewriteCond that matches the old domain name followed by a RewriteRule that redirects to the new domain. For Nginx, add a new server block with server_name set to the old domain and a return 301 directive pointing to the new domain. Both approaches redirect all pages on the old domain to their equivalents on the new domain.

How do I test my redirects?

Use curl -I https://old-domain.com/page to check the HTTP response headers. Look for the 301 or 302 status code and the Location header pointing to your intended destination. You can also use browser developer tools (Network tab) to see the redirect chain. For testing multiple rules, tools like Screaming Frog can crawl and verify hundreds of redirects at once.

What is the difference between 302 and 307?

Both are temporary redirects. The key difference is that 307 guarantees the request method is preserved -- a POST request will remain POST after the redirect. A 302 historically allowed browsers to change POST to GET, which can break form submissions. Use 307 when you need method preservation, 302 for simple page redirects.

htaccessnginxredirect301302rewriteurlserverapacheweb

More Tools You Might Like

πŸ“Word Counter
πŸ”‘JWT Debugger
🟦CSS Flexbox & Grid Sandbox
πŸ”·JSON to TypeScript Generator
.*RegEx Toolkit β€” Visualize, Extract & Replace
⏱️Crontab Expression Visualizer