Skip to content
Advertisement

rewrite URL and get parameter

at the moment I have this url format:

www.domain.de/?paramter=value

with php I can access the value like this:

<? echo $_GET['paramter']; ?>

but I would like to rewrite the url to this format:

www.domain.de/paramter=value

How can I realize this with a htaccess line and how can I access it with php after rewrite ?

Advertisement

Answer

www.domain.de/paramter=value

is a pretty strange way of putting values. However, whenever a user enters such URL, you can make sure that the user lands on the correct page via below .htaccess on Apache server

RewriteEngine On
RewriteRule ^/?([^=]+)=(.+)$ /?$1=$2 [L,NC,R=302]

Demo: https://htaccess.madewithlove.be?share=53dc007b-3781-4d1d-80c6-5f0234cdf11a

This way, your PHP code is intact and nothing needs to be changed on the backend code. If you wish to make a permanent redirection, make R = 301.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement