Hide Get Parameter using .htaccess

1.7k Views Asked by At

Here is my page

xyz.com?show=page

Inside my index.php the code will be like

<?php
echo $_GET['show']
?>

But i want users to type only xyz.com/page and it should automatically append ?show in url

How can i do this ?

I have .htaccess like

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

But it removes only the last part of page i.e., .php

How can i do this

1

There are 1 best solutions below

2
On BEST ANSWER

If index.php will be handling all your requests, you need to rewrite them index.php. What you're doing now is rewriting them to the current request and adding a .php at the end.

This should do what you want:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ /index.php?show=$1 [NC,L]