skip to Main Content

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

2

Answers


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

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search