'.htaccess Reroute file with hidden parameter to another file
I have a problem which I'm trying to solve nor for hours.
So in my root director i have a folder called plugins
with some files in it. The important ones are plugins.php
and query.php
.
When the url is /test/plugins I wan't to show the content of plugins.php
. But when the URL is /test/plugins/param I wan't to keep this URL in the browser but want to show the content of query.php
and use param with $_GET['param'] in it. Is this possible?
My latest and most promising .htaccess file looks like this:
RewriteBase /test/
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^(.*)$ query.php?param=$1 [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ query.php [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^(.*)$ query.php [QSA,NC,L]
Solution 1:[1]
With your shown samples and attempts, please try following htaccess rules file. Make sure to keep your htaccess rules file inside plugins folder and also make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteRule ^test/plugins/?$ plugins.php [QSA,NC,L]
RewriteRule ^test/plugins/param/?$ query.php [QSA,NC,L]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | RavinderSingh13 |