First time doing the URL rewrite using .htaccess using XAMPP and seen other post here somewhere similar. This post provide me enough ideas URL rewriting with PHP but for some reason my attempt failed.
Starting from the conf setup, activating LoadModule rewrite_module modules/mod_rewrite.so and AllowOverride All all instance.
Establishing the requirements such as:
redirect all subfolders request to
404.phpwhich is setting in the root folder.rewrite url for example
http://localhost/mysite/sales.php?a=new&id=0tohttp://localhost/mysite/sales/new/0orhttp://localhost/mysite/sales.php?a=open&id=456tohttp://localhost/mysite/sales/open/456
The .htaccess file:
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine on
#position at the end !
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ 404.php [L] #redirect to 404 page and terminate the process
#For item 2 solution
RewriteRule ^mysite/sales/([A-Za-z0-9-\.]+)/([A-Za-z0-9-\.]+)/?$ sales.php?a=$1&id=$2 [L]
</IfModule>