Alexander Bayerl
Alexander Bayerl

Reputation: 48

Htaccess rule for a rewrite with parameters

So my current URL is: https://example.com/uDoc?id=xx

Using the rewrite, I'd like it to be https://example.com/display?id=xx&type=doc

The real problem is, that because I also have a rule(RewriteRule (.*) $1.php [L]) for silently adding the .php (uDoc?id=xx -> uDoc.php?id=xx, without it, it would result in a 404 error). Which is somewhat interfering with the current answer given.

I have fiddled around with various htaccess rules, but I got no good results :(

I'd really appreciate it if someone could help me, when it comes to htaccess rules, I'm totally giving up...

Upvotes: 1

Views: 71

Answers (1)

anubhava
anubhava

Reputation: 784918

You can use this rule in your root .htaccess:

RewriteEngine On

RewriteRule ^uDoc/?$ display?type=doc [L,QSA,NC]

QSA flag ensures your existing query string i.e. id=xx is carried over to new URI.

Upvotes: 2

Related Questions