URL Rewrite Generator

Create powerful rewrite rules for Apache, Nginx, IIS and other web servers. Generate clean URLs, implement redirects, and enhance your site's SEO.

Use regular expressions to match URLs. Example: ^products/([0-9]+)$
Use $1, $2, etc. to reference captured groups from the source pattern
Internal Rewrite
Redirect
Proxy
Apache
Nginx
IIS
.htaccess
Advanced Options
Rewrite Rule
Your rewrite rule will appear here

Test Your Rewrite Rule

Test results will appear here

Our URL Rewrite Tool provides web developers and server administrators with a comprehensive solution for creating and managing URL rewrite rules across different web servers. This essential tool helps you generate clean, SEO-friendly URLs, implement proper redirects, and maintain website structure while ensuring optimal server performance. Whether you're migrating websites, improving SEO, or implementing RESTful APIs, this tool offers precise rule generation with real-time validation and testing capabilities.

SEO Benefits of URL Rewriting

URL rewriting is essential for creating SEO-friendly URLs that are easy for users and search engines to understand. Clean URLs improve click-through rates and help search engines better understand your site structure.

Improved Rankings

Keywords in URLs can positively impact search rankings for relevant queries. Search engines use URL text as a ranking factor.

Better User Experience

Clean URLs are easier to read, remember, and share. Users are more likely to click on descriptive URLs in search results.

Link Building

Descriptive URLs are more likely to be used as anchor text when others link to your content, improving SEO value.

Best Practice: Use hyphens to separate words in URLs (e.g., /my-great-product) rather than underscores or spaces. Hyphens are treated as word separators by search engines.

Common Rewrite Patterns

Clean URLs
Convert dynamic URLs to static-looking paths
Source: ^products/([a-z0-9-]+)$ Target: product.php?slug=$1
Trailing Slash
Ensure consistent trailing slash usage
Source: ^(.*)/$ Target: $1 [R=301]
WWW to Non-WWW
Redirect www to non-www version
Source: ^www\.example\.com Target: example.com [R=301]
HTTPS Enforcement
Redirect HTTP to HTTPS
Condition: HTTPS off Target: https://%{HTTP_HOST}%{REQUEST_URI} [R=301]
Remove File Extensions
Hide .php/.html extensions
Source: ^(.*)\.html$ Target: $1.php
Pagination
Clean pagination URLs
Source: ^blog/page/([0-9]+)$ Target: blog.php?page=$1

Implementation Guide

Apache .htaccess

Add the following code to your .htaccess file:

RewriteEngine On RewriteRule ^products/([0-9]+)$ product.php?id=$1 [L]

Make sure to enable the rewrite module in your Apache configuration:

sudo a2enmod rewrite sudo systemctl restart apache2

Nginx Server Config

Add the following code to your server block in nginx.conf:

location / { try_files $uri $uri/ @rewrite; } location @rewrite { rewrite ^/products/([0-9]+)$ /product.php?id=$1 last; }

After updating the configuration, reload Nginx:

sudo nginx -t sudo systemctl reload nginx

IIS Web.config

Add the following code to your web.config file:

<system.webServer> <rewrite> <rules> <rule name="Product Rewrite"> <match url="^products/([0-9]+)$" /> <action type="Rewrite" url="product.php?id={R:1}" /> </rule> </rules> </rewrite> </system.webServer>

Ensure the URL Rewrite module is installed in IIS.

Important: Always test your rewrite rules in a development environment before deploying to production. Incorrect rules can cause website downtime.

About URL Rewriting

URL rewriting is a technique that allows web servers to modify URLs before processing requests. This enables the creation of clean, user-friendly URLs that map to underlying application logic.

When to Use URL Rewriting

  • Creating clean, SEO-friendly URLs: Convert dynamic URLs like "product.php?id=123" to "/products/123"
  • Migrating from an old URL structure to a new one: Maintain SEO value when changing site structure
  • Hiding technical implementation details: Protect your technology stack from being exposed
  • Implementing vanity URLs for marketing campaigns: Create memorable URLs like "/special-offer"
  • Creating RESTful API endpoints: Structure URLs for API resources like "/api/users/{id}"
  • Handling legacy URLs after site redesigns: Redirect old URLs to new locations

Best Practices

1

Keep URLs descriptive and keyword-rich: Use meaningful words that describe the content. For example, "/digital-camera-sony-a7" is better than "/product/123".

2

Maintain consistency: Use a consistent URL structure across your entire site. This helps users navigate and search engines understand your site hierarchy.

3

Avoid unnecessary parameters: Keep URLs as simple as possible. Remove unnecessary query parameters that don't affect content.

4

Use hyphens to separate words: Hyphens are more SEO-friendly than underscores. Search engines treat hyphens as word separators.

Common Mistakes to Avoid

  • Case sensitivity issues: URLs are case-sensitive on some servers. Always use lowercase consistently.
  • Redirect chains: Multiple redirects in sequence (A → B → C) slow down page loading and can dilute SEO value.
  • Canonicalization issues: Multiple URLs pointing to the same content can dilute SEO value. Use canonical tags or redirects to consolidate.
  • Overly complex regex: Difficult to maintain and debug. Keep regular expressions as simple as possible.
  • Forgetting to test: Always test rewrite rules thoroughly in a development environment before deploying to production.

Frequently Asked Questions

Q: What's the difference between URL rewriting and redirecting?

A: URL rewriting changes the URL internally without the browser knowing. Redirecting sends the browser to a new URL with an HTTP status code.

Q: How do I debug rewrite rules that aren't working?

A: Enable rewrite logging on your server, start with simple rules, and test incrementally. Use our Test Rule feature to verify behavior before implementing.

Q: Can URL rewriting affect website performance?

A: Complex rewrite rules can add overhead, but for most sites the impact is negligible. Avoid overly complex regex patterns and redirect chains.

Advertisement
Ad Space (300x250)

Related Tools

Advertisement
Ad Space (300x600)

Common Rewrite Flags

  • L Last rule - stop processing further rules
  • NC Case-insensitive matching
  • R Redirect to new URL
  • QSA Append query string from original request
  • NE No escaping of special characters
  • F Forbidden (403) response
  • G Gone (410) response

URL Structure Best Practices

  • Use descriptive words in URLs
  • Keep URLs short and meaningful
  • Use hyphens to separate words
  • Avoid unnecessary parameters
  • Implement consistent trailing slash policy
  • Use lowercase letters consistently
  • Avoid session IDs in URLs