search

Home  >  Q&A  >  body text

htaccess url rewriting without losing url parameters

I created an htaccess URL rewrite to change my URL webseite.com/dashboard.php to webseite.com/dashboard.

My problem is that when I visit certain sites of my website (like https://example.com/detail_user.php?id=1), I provide parameters via the url (using in database data).

According to my rewrite rules, it ignores parameters added to the URL.

Is there any htaccess rule that can provide parameters to a url but remove the .php ending when accessing a normal site?

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

P粉982881583P粉982881583308 days ago524

reply all(1)I'll reply

  • P粉724737511

    P粉7247375112024-01-11 10:12:21

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

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

    QSA means "query string append", if a query string was passed in the original URL, it will be appended to the rewrite.

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

    reply
    0
  • Cancelreply