There’s no way, but by making a beautiful which in my view is unnecessary, the use of querystrings (?....
) is just this, carry variables via URL for links use (Urls), if you are looking to make the URL look more beautiful really think you are worrying about something totally superfluous.
The way you can prevent the URL from changing is not to use the URL, switch with Ajax, using maybe a modal, for example with Bootstrap and <iframe >
(or ajax) and the other would be using POST or even URL friendly
An example using Bootstrap with the attribute target=""
:
.modal-body > .editpage {
border: none;
width: 100%;
height: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<a href="edita.php?id=1" target="name" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
Editar produto 1
</a>
<a href="edita.php?id=2" target="name" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
Editar produto 2
</a>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<iframe src="about:blank" name="info" class="editpage"></iframe>
</div>
</div>
</div>
</div>
Using POST
In html it would look like this:
<form method="POST" action="edita.php">
<input type="hidden" name="id" value="1">
<button>Editar 1</button>
</form>
<form method="POST" action="edita.php">
<input type="hidden" name="id" value="2">
<button>Editar 2</button>
</form>
In php I would trade for this:
<?php
if (empty($_POST['id'])) {
die('Falta o id');
}
$id = $_POST['id'];
It does not affect at all the use of POST and GET, but really POST has a lot of behaviors that can make you wonder, I’m not saying it’s right or wrong, but using something just to beautify the Urls is a little unnecessary.
URL friendly
If you use apache and have the rewrite module enabled you can use friendly urls too, of course it does not improve at all, at most reading, after all it makes no sense to index google editing pages
create a .htaccess
thus:
RewriteEngine on
RewriteRule ^edit/(\d+)$ edita.php?id=$1 [QSA,L]
On IIS in the web.config
:
<rewrite>
<rules>
<rule name="editar" stopProcessing="true">
<match url="^edita/(\d+)" />
<action type="Rewrite" url="edita.aspx?id={R:1}" />
</rule>
</rules>
</rewrite>
Or Nginx:
location /edit {
rewrite ^/edit/(\d+)$ /edita.php?id=$1 break;
}
So it will direct Urls in format http://site/edit/1
, http://site/edit/2
and http://site/edit/1001
for http://site/edit/edita.php?id=1
, http://site/edit/edita.php?id=1
, etc..
I’m not from php area, but take a look at these 2 links: Stack Overflow Stack Overflow Note here that the suggestion is similar, make a form (Dynamic or not) and use input’s Hidden with the parameter in the input Value and use the post method.
– Bruno
post
– adventistaam