I’m trying to generate seo friendly urls using a htaccess file and PHP. But it’s not working.
I tried the code below in localhost (running XAMPP)
RewriteEngine On
RewriteBase /real/
RewriteRule ^property-details/([0-9a-zA-Z]+) property-details.php?pid=$1 [NC, L]
2
Answers
You need to remove the space between your
RewriteRule
flags. This will result in a 500 Internal Server error – in which case you should examine your error logs for a more meaningful error. It should be written as:No spaces.
UPDATE:
For mod_rewrite to work in per-directory .htaccess files,
FollowSymLinks
must also be enabled (if its not already). At the very top of your .htaccess file, include:There are different ways of achieving the same results, but this will give you a guide.
First activate mod_rewrite uncommenting this line in you httpd.conf or apache2.conf file:
Change AllowOverride from none to All to your www directory
Restart apache:
or
In your www folder, create an .htaccess file and add this:
Then in your index.php file: