Mod URL with htaccess?

Gregg

Geek Trainee
Hello all,

I'm having a great difficulty understanding how to use the url rewrite capability of htaccess.. this is what I would like to do:

Convert the user typed url: www.something.com/about/
Into: www.something.com/index.php?p=about

With much thanks, could anybody tell me how I could do this?

Also, while we're discussing htaccess, I am wondering if its possible to redirect any 404 error..or any error for that matter to the homepage with errors.. (www.something.com/index.php?p=errors)

Thanks guys, you're great!
 
.htaccess rules can be tricky, thats why I prefer do it how wordpress does it.

.htaccess
Code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

then in your index.php

PHP:
<?php

echo '<pre>';
print_r($_SERVER);
echo '</pre>';

$path = trim($_SERVER['REQUEST_URI'], '/');

if ($path == 'about')
{
  echo  'about page';
  //or include('about.php');
  //or go into the database to get the page contents
}
 
Back
Top