URL Rewriting Tool - Generate and Test Rewrite Rules

URL Rewriting Tool

Generate, test, and optimize URL rewrite rules for Apache and Nginx

Note: Always test rewrite rules in a staging environment before deploying to production. Keep backups of your configuration files.
Your website domain (optional)
The URL pattern you want to rewrite from
The URL you want to rewrite to
URL to test against the rewrite rule
Paste your rewrite rule here
Common Rewrite Rule Templates

Click on a template to copy the code to your clipboard


Warning: Undefined variable $uri in /home/ammour/web/seositecheckup.eu/public_html/tools/link/url-rewriting-tool.php on line 366

Warning: Undefined variable $uri in /home/ammour/web/seositecheckup.eu/public_html/tools/link/url-rewriting-tool.php on line 366

Warning: Undefined variable $uri in /home/ammour/web/seositecheckup.eu/public_html/tools/link/url-rewriting-tool.php on line 366

Warning: Undefined variable $query_string in /home/ammour/web/seositecheckup.eu/public_html/tools/link/url-rewriting-tool.php on line 366

Warning: Undefined variable $uri in /home/ammour/web/seositecheckup.eu/public_html/tools/link/url-rewriting-tool.php on line 372

Warning: Undefined variable $uri in /home/ammour/web/seositecheckup.eu/public_html/tools/link/url-rewriting-tool.php on line 372

Warning: Undefined variable $query_string in /home/ammour/web/seositecheckup.eu/public_html/tools/link/url-rewriting-tool.php on line 372

Warning: Undefined variable $invalid_referer in /home/ammour/web/seositecheckup.eu/public_html/tools/link/url-rewriting-tool.php on line 390
HTTP to HTTPS

Force all traffic to use HTTPS

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
WWW to Non-WWW

Redirect www to non-www domain

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Remove File Extension

Access PHP files without .php extension

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
Pretty URLs for CMS

Route all requests through index.php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
Old URL to New URL

301 redirect old page to new page

Redirect 301 /old-page.html /new-page.html
Block IP Address

Deny access from specific IP

Order Allow,Deny
Allow from all
Deny from 192.168.1.1
Block Hotlinking

Prevent image hotlinking from other sites

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^https?://(www\.)?example\.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [F,NC,L]
Canonical URL

Redirect to canonical URL

RewriteCond %{THE_REQUEST} /index\.html [NC]
RewriteRule ^index\.html$ / [R=301,L]
URL Rewriting Guide
What is URL Rewriting?

URL rewriting is a server-side technique that modifies incoming URL requests before they are processed. It's commonly used for creating SEO-friendly URLs, redirecting old URLs to new ones, and implementing clean URL structures.

Benefits
  • ✓ Better SEO with clean, descriptive URLs
  • ✓ Improved user experience
  • ✓ Hide implementation details
  • ✓ Maintain links during site migration
  • ✓ Enforce HTTPS and canonical URLs
Common Flags
[L] Last rule (stop processing)
[R=301] Permanent redirect
[R=302] Temporary redirect
[QSA] Append query string
[NC] Case insensitive
[F] Forbidden (403)

Best Practices
Practice Recommendation
Use 301 for Permanent Always use 301 redirects for permanent URL changes to preserve SEO value
Minimize Redirects Avoid redirect chains. Point directly to final destination
Test Thoroughly Test all rewrite rules in staging before production deployment
Keep Backups Always backup .htaccess or nginx.conf before making changes
Use Hyphens Use hyphens (-) not underscores (_) in URLs for better SEO
Lowercase URLs Keep URLs lowercase to avoid duplicate content issues