Hey everybody! I’m new to .htaccess and today, I tried to make the tutorial about Clean URLs with Apache. I am not sure, why it doesn’t show a clean url. I will show you the code of my example and what I changed in the “httpd.conf” file.
Firstly, I opened the httpd.conf file to clean the symbol in front of this row “LoadModule rewrite_module modules/mod_rewrite.so”.
Secondly, I created a new file within my htdocs folder called “index.php”.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
body {
font: 11px Arial;
color: #000;
}
a {
text-decoration: none;
color: #000;
padding-left: 5px; padding-right: 5px;
}
a:hover {
color:#ff0000;
}
</style>
</head>
<body>
<h1>.htaccess</h1>
<p><a href="index.php?category=home">Home</a> | <a href="index.php?category=about">About<strong>Me</strong></a> | <a href="index.php?category=work">Work</a> | </p>
<hr style='border: none; border-top: 2px solid #000;' />
<?
if (isset($_GET['category'])) {
$file = $_GET['category'] . ".php";
if(file_exists($file)) {
include $file;
} else {
echo 'Page not found!';
}
} else {
include("home.php");
}
?>
</body>
</html>
Thirdly, I created the other files called “home.php, about.php, work.php”.
A last, I created the file “.htaccess” with the same code like in the tutorial.
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9\-]+)/?$ index.php?category=$1 [L,QSA]
RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/?$ index.php?category=$1&page=$2 [L,QSA]
RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/?$ index.php?category=$1&page=$2§ion=$3 [L,QSA]
Thanks!