Home > Back-end >  htaccess url rewrite without loosing url parameters
htaccess url rewrite without loosing url parameters

Time:11-12

i have created a htaccess url rewrite to geht my urls webseite.com/dashboard.php to webseite.com/dashboard.

My Problem is, that I am giving parameters (for database data) over my url when I visit certain sites of my website like https://example.com/detail_user.php?id=1.

With my rewrite rules it ignores the parameters added to the url.

Is there any htaccess rule to give parameters to an url but when visiting the normal site remove the .php ending?

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^/] )/$ $1.php

CodePudding user response:

I think what you are looking for is to append [QSA].

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^/] )/$ $1.php [QSA]

QSA means "Query String Append", if there's a query string passed with the original URL, it will be appended to the rewrite.

In your use case, /detail_user.php?id=1 becomes /detail_user?id=1

CodePudding user response:

RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule (.)/(.)?$ $1.php?$2

  • Related