0
$url = example.com/your-new-key-is.php?key=5&submit=success

The above url consists query string and submit value, also it's not user friendly

Once I click the submit the new url want to be like that

$url = example.com/your-new-key-is-5/

I want to replace the key url with value(5) and truncate the part followed & symbol.

Anybody knows the answer ?

AymDev
  • 6,626
  • 4
  • 29
  • 52

2 Answers2

0

You need to use mod rewrite. There are ways to write them. You can also use a rewrite rule generator to understand how its done.

Below are the rules that needs to go into the .htaccess file

# Rewrite --- example.com/your-new-key-is.php?key=5&submit=success => example.com/your-new-key-is-5/

RewriteCond %{QUERY_STRING} (^|&)key=5($|&)
RewriteCond %{QUERY_STRING} (^|&)submit=success($|&)
RewriteRule ^example\.com/your-new-key-is\.php$ /example.com/your-new-key-is-5/?&%{QUERY_STRING}

Here is a link to the Generator.

http://www.visiospark.com/mod-rewrite-rule-generator/

After you've written the rule to htaccess, you will enter in example.com/your-new-key-is-5/ which is equivalent to example.com/your-new-key-is.php?key=5&submit=success

unixmiah
  • 3,081
  • 1
  • 12
  • 26
  • i have loaded nearly 150 numbers with in select box. The user will select the value from the list and click submit. The process is dynamic, so i want the dynamic method – user1973141 Aug 10 '18 at 04:20
  • you can do this by looking at this example https://stackoverflow.com/questions/18162686/url-rewrite-get-parameters – unixmiah Aug 10 '18 at 15:07
0

I think you can:

$url1 = example.com/your-new-key-is.php?key=5&submit=success

$url2 = example.com/your-new-key-is-5/

<?php
$url= str_replace($url1 , $url2);
?>

You can see more examples here: function.str-replace.php

Skatt
  • 372
  • 3
  • 10