Developer Tools
URL Rewriting Tool for Apache mod_rewrite Rules
Turns a dynamic URL into a clean URL and the Apache rewrite rule that serves it.
URL Rewriting Tool tool
Turn a dynamic URL into a clean one
Paste a URL with a query string, then press Generate to get two clean URL styles and their mod_rewrite rules.
How to use
- Paste a dynamic URL that has a query string, such as /product.php?id=123.
- Click Generate to get two clean URL styles and their mod_rewrite rules.
- Copy one rule into the
.htaccessfile in your site root. Keep only one RewriteEngine On line per file. - Apache must allow .htaccess overrides for that folder (AllowOverride FileInfo is enough for mod_rewrite).
About the URL Rewriting Tool
A URL such as /index.php?category=shoes&id=456 works for a server and means nothing to a visitor. Apache's mod_rewrite module can show /shoes/456 instead, but its rule syntax trips up even experienced developers. Kwebby's URL Rewriting Tool turns a dynamic URL into a clean URL and the mod_rewrite rule that serves it. You paste the URL, click Generate and copy the rule into your .htaccess file.
Key Takeaways
- Kwebby's URL Rewriting Tool takes a dynamic URL with a query string, such as /product.php?id=123&cat=shoes, and returns two clean URL styles, each with an Apache mod_rewrite rule ready for your .htaccess file.
- A rewrite changes the URL inside the server while the visitor's address bar stays the same. A redirect sends the browser to a new URL and the address bar changes.
- Three building blocks drive most rules:
RewriteEngine On,RewriteRuleandRewriteCond. Flags such as[L],[R=301],[QSA]and[NC]control what happens next. - Apache ignores .htaccess files unless
AllowOverridepermits them. For rewrite rules,AllowOverride FileInfois enough, and Apache's own guidance says to use the main server configuration when you have access to it. - Google advises readable words over long ID numbers in URLs and hyphens over underscores.
- Test every new rule before you rely on it, because one typo in .htaccess can break a site.
What Is the Kwebby URL Rewriting Tool?
The Kwebby URL Rewriting Tool is a free web tool that converts a dynamic URL into Apache mod_rewrite rules for your .htaccess file. You paste a URL with a query string and click Generate. The tool returns two clean URL styles and a rule for each, which you copy into your server's .htaccess file. No regular expression writing is needed, and the tool runs in your browser.
URL rewriting means the server transforms one URL pattern into another without the browser seeing the change. Visitors see a clean address, while the server still runs the dynamic script behind it.
Key Features and How It Works
The tool takes one input and returns two clean URL styles, each with its rule. The explanation below shows what each part does.
One Field, One Button
The form has a "Dynamic URL to Convert" field and a Generate button. Paste a URL that has a query string and click Generate. There are no extra settings to configure first. A URL with no query string returns a message asking for a dynamic URL.
Two Clean URL Styles
For https://example.com/product.php?id=123&cat=shoes, the tool returns:
- Type 1, single page style:
/product-id-123-cat-shoes.htmlwith the ruleRewriteRule ^product-id-([^/]+)-cat-([^/]+)\.html$ /product.php?id=$1&cat=$2 [L,QSA]. - Type 2, directory style:
/product/id/123/cat/shoes/with the ruleRewriteRule ^product/id/([^/]+)/cat/([^/]+)/?$ /product.php?id=$1&cat=$2 [L,QSA].
Each rule starts with RewriteEngine On. Every captured value is passed back to the script as $1, $2 and so on, [L] stops further rules and [QSA] keeps any extra query string. The rule is an internal rewrite, so the clean URL stays in the address bar. The tool does not write RewriteCond lines, optional parameters or redirects from the old URL.
Example URLs to Try
The page offers three sample URLs: /product.php?id=123&cat=shoes, /index.php?category=news&page=2 and /shop/item.php?sku=A100. Run one of them first if you have not used mod_rewrite before.
mod_rewrite Output for .htaccess
The result is written for Apache's mod_rewrite module, the standard way to rewrite URLs on Apache servers. WordPress uses the same module to serve /category/post-title instead of /index.php?p=123.
Built-In Setup Steps
The page lists the setup steps next to the tool: paste the URL, click Generate, copy one rule into .htaccess with only one RewriteEngine On line per file, and make sure Apache allows .htaccess overrides for that folder. AllowOverride FileInfo is enough for mod_rewrite.
Why Clean URLs Matter
Clean URLs are easier for visitors to read, trust and share, and they are easier for search engines to understand. Google's guide to URL structure recommends readable words rather than long ID numbers, and it prefers hyphens over underscores to separate words.
Parameters cause a second problem. Google warns that URLs with session IDs, tracking parameters and endless filter combinations create URL sprawl and waste crawler bandwidth. Rewriting dynamic URLs into stable paths is one way to reduce that.
How mod_rewrite Rules Work
A rule has three parts: a switch, a pattern and a result. The tool writes them for you, but you should know how to read them.
RewriteEngine On
This directive switches the rewrite engine on. Place it near the top of your .htaccess file. Without it, every RewriteRule is ignored.
RewriteRule
RewriteRule pattern substitution [flags] is the core directive. The pattern is a regular expression that matches the incoming URL. The substitution is what the server uses instead. Flags change the behavior.
RewriteCond
A RewriteCond line sets a condition that must be true before the next RewriteRule applies. Rules use it to check server variables, to test whether a file exists or to exclude certain paths.
Common Flags
The Apache documentation on RewriteRule flags defines them. These are the ones you will see most:
[L]: last rule. Processing of the rule set stops when the rule matches.[R=301]: redirect the browser. Apache uses a 302 by default if you give no code.[QSA]: append the original query string to the new URL instead of replacing it.[NC]: make the pattern case-insensitive.[F]: return 403 Forbidden.
How to Use the URL Rewriting Tool
Creating a rule takes five steps.
- Paste the URL. Paste a dynamic URL with a query string into the "Dynamic URL to Convert" field, or click one of the "Try" examples.
- Click Generate. The tool shows two clean URL styles and a mod_rewrite rule for each.
- Copy one rule into .htaccess. Open your site's .htaccess file, keep a single
RewriteEngine Online near the top, and paste the RewriteRule below it. - Check AllowOverride. Make sure Apache allows overrides for the folder, for example
AllowOverride FileInfoin your virtual host configuration. Without it, Apache ignores .htaccess files. - Test the rule. Load the clean URL in a browser and confirm the right page appears. Use the Server Status Checker to confirm it returns a 200.
Best Practices for URL Rewriting
Rewrite rules are small, but a mistake can take a whole site down. These habits reduce the risk.
Choose Rewrite or Redirect on Purpose
Use a rewrite when you want to show a clean URL and keep the old script running. Use a redirect when a page has moved and you want browsers and search engines to follow it. If you need a redirect, the .htaccess Generator is built for it. The common mistake is to use a redirect flag where you wanted a silent rewrite, which changes the address bar.
Use Simpler Directives When They Fit
Apache's guide on when not to use mod_rewrite calls mod_rewrite a last resort and points to simpler options such as Redirect, Alias and FallbackResource. Reach for mod_rewrite when you need pattern matching or when .htaccess is all you can edit.
Back Up .htaccess Before Every Edit
Copy the file before you paste a new rule. A syntax error in .htaccess can return a 500 error for the whole site, and a backup lets you restore it in seconds.
Prefer the Main Server Configuration When You Can
Apache's .htaccess how-to says to put configuration in the main server config if you have access, because .htaccess lookups cost performance on every request. Shared hosting often gives you only .htaccess, and that is a valid reason to use it.
Order Rules From Specific to General
Rules run in order. Put narrow rules first and broad catch-alls last, and add [L] where processing should stop. A broad rule placed first can swallow requests meant for a later one.
Test With Real URLs
Try the new clean URL, the old dynamic URL and a URL that should not match. Look for redirect loops and wrong pages before you leave the site live.
Common Use Cases
- Clean product or category URLs. Show
/products/123/detailswhile the server still runs a script with query parameters. - Legacy URL patterns. Map old URL structures to the current scripts after a redesign.
- CMS-style permalinks. Recreate the permalink behavior that WordPress and many PHP applications use.
- User-friendly profile paths. Present
/user/profile/settingsstyle paths for application pages. - Canonical URL cleanup. Route variants of a URL to one preferred form.
Related Kwebby Tools
URL rewriting touches several parts of server setup. These tools in our Developer Tools collection help with the rest:
- .htaccess Generator builds redirects, HTTPS rules, security headers and caching rules for Apache.
- Nginx Config Generator covers Nginx servers, which do not read .htaccess files.
- WWW Redirect Checker traces redirect chains so you can test what your rules actually do.
- Regex Generator builds regular expressions for URL patterns, useful when you write RewriteRule patterns by hand.
- URL Encoder / Decoder encodes and decodes URLs and query strings before you place them in a rule.
Final Thoughts
A clean URL takes one rule, and a wrong rule can take a site down. The URL Rewriting Tool gives you a starting rule in seconds, and the habits above keep it safe: back up, add one rule at a time, and test the result. Generate a rule from one of the example URLs today, try it on a staging site, and then move on to your real URLs. If you need a redirect instead, open the .htaccess Generator.
FAQ
Frequently asked questions
What is URL rewriting?
URL rewriting is a server-side change from one URL pattern to another that the visitor does not see. It turns an address like /index.php?id=123 into a readable one like /products/123. Clean URLs help users and are easier for search engines to read.
What is mod_rewrite?
mod_rewrite is an Apache module that rewrites URLs using rules based on regular expressions. You usually place the rules in an .htaccess file or in the server configuration. WordPress and many other PHP applications use it.
What is the difference between a rewrite and a redirect?
A rewrite maps the request to a different resource inside the server, and the address bar does not change. A redirect tells the browser to request a new URL, and the address bar changes. Use rewrites for clean URLs and redirects for moved pages.
Why are my .htaccess rewrite rules not working?
Check three things first: the rewrite module must be enabled, RewriteEngine On must appear above your rules, and AllowOverride must permit .htaccess files. Apache's default for AllowOverride is None, which makes it ignore .htaccess files entirely. A hosting provider can enable mod_rewrite if it is off.
Does this work on Nginx servers?
No. The generated rules are for Apache's mod_rewrite and .htaccess. For Nginx, use the Nginx Config Generator to create rewrite and redirect rules in Nginx syntax.
Is the URL Rewriting Tool free?
Yes. The tool is free and needs no account. Paste a dynamic URL and click Generate.
Kwebby builds software too
Need a website or app built?
Get 50% off your first project. The discount applies to your first fixed quote only. Kwebby has delivered 1,200+ projects on fixed quotes from $100.