0

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:

  1. redirect all subfolders request to 404.php which is setting in the root folder.

  2. rewrite url for example http://localhost/mysite/sales.php?a=new&id=0 to http://localhost/mysite/sales/new/0 or http://localhost/mysite/sales.php?a=open&id=456 to http://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>
  • And what is your actual question? – arkascha May 19 '23 at 19:09
  • "redirect all subfolders request to 404.php" - So, a request for any physical subdirectory should trigger a 404? (As opposed to a 301 or 403?) What URL(s) are you currently linking to? – MrWhite May 20 '23 at 01:02
  • I thought it was good idea to use a single page (404) when the website received an error request ie directory listing, file listing, etc. Thanks for the comment – Nathan DevX May 20 '23 at 04:00

0 Answers0