mod_rewrite Setup URL Configuration Guide
In this guide, you will learn how to enable the mod_rewrite module on the Apache web server and create SEO-compatible, clean URL structures using .htaccess.
Thanks to the URL rewrite system:
- Complex query string structures are simplified
- SEO performance increases
- User experience improves
- More professional URL structures are created
What is mod_rewrite?
Apache mod_rewrite is a powerful module that rewrites incoming URL requests according to rules.
Example:
/urun.php?id=5
instead of:
/urun/5
SEO compatible URLs such as SEO can be created.
Prerequisites
Before starting the installation:
- Ubuntu 22.04 server
- Apache Web Server installed
- user with sudo privilege
1. Activating Apache mod_rewrite Module
To enable mod_rewrite module:
sudo a2enmod rewrite
Restart the Apache service:
sudo systemctl restart apache2
2. Enabling .htaccess Usage
Apache disables .htaccess by default.
Edit the VirtualHost file to open it:
sudo nano /etc/apache2/sites-available/000-default.conf
AllowOverride Setting
Aşağıdaki bloğu ekleyin:
<VirtualHost *:80>
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Restart Apache:
sudo systemctl restart apache2
3. Creating .htaccess File
Create the file .htaccess:
sudo nano /var/www/html/.htaccess
Activate the rewrite engine:
RewriteEngine On
4. Basic RewriteRule Example
Purpose
/hakkimizda → hakkimizda.html
``` id="h1t8qp"
HTML Dosyası
sudo nano /var/www/html/aboutus.html
<html>
<head>
<title>About Us</title>
</head>
<body>
<h1>About Our Website</h1>
</body>
</html>
Rewrite Kuralı
Add in .htaccess:
RewriteEngine On
RewriteRule ^about us$ about us.html [NC,L]
Description:
NC → Case insensitive
L → Last rule (take no further action)
5. SEO Dostu Dinamik URL Yapısı
Eski URL:
result.php?product=shirt&season=summer
``` id="p4x7qd"
New URL:
/gomlek/yaz
RewriteRule:
```apache id="l2v8qp"
RewriteRule ^([A-Za-z0-9]+)/([a-z]+)$ result.php?product=$1&season=$2 [QSA,L]
Description:
$1 → product name
$2 → season
QSA → preserves existing query string
6. Redirecting Broken Pages (SEO 301)
Amaç
Redirecting non-existent pages to the home page
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . / [R=301,L]
Description:
!-f → if not file
!-d → if not folder
R=301 → permanent redirect (critical for SEO)
Frequently Asked Questions (FAQ)
mod_rewriteWhy is it important for SEO?
Search engines index clean and meaningful URLs better.
Does
.htaccessaffect performance?
Yes, it creates a small overhead, but it is usually not noticeable on modern servers.
What is the difference between RewriteRule and Redirect?
Redirect → Simple redirect RewriteRule → Advanced URL manipulation
Why is 301 important for SEO?
It preserves page value (link juice) and prevents ranking loss.
Result
With Apache mod_rewrite:
You can create SEO compatible URL structures You can modernize old URLs You can improve user experience
This structure is especially critical for SEO projects, blog systems and e-commerce sites.
For more advanced Apache configurations, you can use the GenixNode infrastructure.

