.htaccess Hide php param keys from url but dont change physical path

I am looking for a solution to hide param keys from my url

for example /page1.php?city=Lahore

I want it to rewrite as /page1/Lahore

but the most important thing is Lahore is not a directory exist on server I want it to point to same file page1.php just rewrite url externally

thanks

Upvotes: 0

Views: 51

Answers (2)

Hassan Saeed
Hassan Saeed

Reputation: 7080

try this code for .htaccess file

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /projectfoldername/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^page1/(.+?)/?$ /projectfoldername/page1.php?key=$1 [L,QSA]

page1.php code will be

<?php 
echo $_REQUEST['key'];  
?>

then call http://localhost/projectfoldername/page1/1947

output will be :1947

Upvotes: 0

Jacky Attias
Jacky Attias

Reputation: 57

create an .htaccess file from the root and paste this code

RewriteCond %{HTTP_HOST} ^(.*)$ [NC]
RewriteRule ^page1/(.*)? /page1.php?city=$1 [L]

or you could also put it in your website apache conf file.

Upvotes: 1

Related Questions