I am testing out mod rewrite for my site. I thought i would try a simple code, but it’s not working. I have a .htaccess file in my root directory (localhost). In localhost I have a page titled profile.php. Profile.php can take a get variable p from my database. So it looks like localhost/profile.php?p=3 where 3 is a unique id. When i go to localhost/profile.php?p=3 it works, but when i go to localhost/3, it doesn’t. I get a 404 not found.
.HTACCESS file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]
RewriteRule ^(.*)$ http://localhost/profile.php?p=$1 [NC]
EDIT:
httpd.conf (currently):
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
</Directory>
Try adding the following to your htaccess file in the root directory of your site
Edit:
Check your httpd.conf to see if
AllowOverrideis set to all as below. If set to none, then .htaccess will not work