Remove question mark added to url using form 'get' method
Solution 1
The ?
probably gets added because you're doing a GET
request from a form.
Why not do something like:
<input type="button" onclick='document.location.href=<?php echo json_encode($url);?>'>;
Solution 2
use POST
method instead of GET
Comments
-
martin almost 2 years
I am using a form and the 'get' method to offer users a return option to an unknown url that they came from within my site, as per the code below. I prefer this to just the browsers back button and it works without javascript.
The problem I am having is that some browsers (chrome, safari, there may be others) are adding a question mark to the end of the url they are referred back to. I don't want this for seo reasons.
My question is either:
1) Can I prevent the question mark within my php code somehow; or
2) Please could somebody show me how to redirect the url using htaccess, I potentially have urls that could end:-
.html? .htm? .php? /?
Thanks in advance.
<?php if (isset ($_SERVER['HTTP_REFERER']) ) { $url = htmlspecialchars($_SERVER['HTTP_REFERER']); echo '<br /><form action="' . $url . '" method="get"> <div id="submit"><input type="submit" value="Return to previous page" /></div> </form>'; } ?>
-
martin almost 11 yearsthanks, but I particularly want it to work without javascript
-
martin almost 11 yearsI don't know the url in advance?
-
Halcyon almost 11 yearsWell, you could always use
POST
:/ -
martin almost 11 yearsYou are correct that GET causes the question mark. I wasn't sure about using POST. Could there be an issue if the destination page already has a POST form for another purpose?
-
Halcyon almost 11 yearsNo, it shouldn't cause an issue but it's not exactly pretty either.
-
Nishan over 10 years... which does totally not help answering the question. Yes, that's how you use RewriteRules, but it does absolutely nothing to remove question marks from the end of the called URL.