Make sure mod_rewrite is turned on. In your httpd.conf file, you should have something similar to:
LoadModule rewrite_module modules/mod_rewrite.so
Then make sure your htaccess file is in your /ch02/
directory.
Question
I am trying to make SEO friendly URLs of using apache mod_rewrite.
My normal URLs is something like this -
index.php?p=about
index.php?p=contact
index.php?p=this
My expecting SEO friendly URLs should be something similar to this -
localhost/php_advance/ch02/about
localhost/php_advance/ch02/contact
localhost/php_advance/ch02/this
I tried it with creating a .htaccess
file and doing some changes to my apache httpd.conf
file.
This is my .htaccess file
<ifModule mod_rewrite.c>
# Turn on the engine:
RewriteEngine on
# Set the base to this directory:
RewriteBase /php_advance/ch02/
# Redirect certain paths to index.php:
RewriteRule ^(about|contact|this|that|search)/?$ index.php?p=$1
</ifModule>
And also, At the end of the httpd.conf
file, I added some code like this -
<Directory "C:/wamp/www/php_advance/ch02">
AllowOverride All
</Directory>
NOTE:
I am using WAMP server and Windows 07
But this coding is not working for me. Hope someone will help me out. Thank you.
Solution
Make sure mod_rewrite is turned on. In your httpd.conf file, you should have something similar to:
LoadModule rewrite_module modules/mod_rewrite.so
Then make sure your htaccess file is in your /ch02/
directory.
OTHER TIPS
Try this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /php_advance/ch02/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /php_advance/ch02/index.php [L]
</IfModule>