Flora D. Flora D. - 17 days ago 6
Apache Configuration Question

Htaccess hide original processing file in php

I am trying to brows localhost/view using apache rewrite rule bellow and i am getting output of 14. But this 14 value is static i want to put value from localhost/view this URL which will processed by test.php?view=$value this url. how to do it?

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^view/?$ test.php?view=14 [NC,L]


actually i need to hide original php file and its get method (test.php?view=) which is actually processing the request.

Answer

You can use a regex capture group to match against dynamic uris :

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^view/(.*)/?$ test.php?view=$1 [NC,L]