SEO friendly urls after submiting a form
What means that?
It means that in a form whit GET method, when you submit, you will be redirected to a new page with “?example=variable” added to the URL.
Think if your users will search on your site some data and wish to place the link with the searched results on blogs,forum will have an ugly URL,but the most of all you will lose characters spaces for more keywords for SEO.
Here is an example:
This is a default form submitted url:
www.example.com/search?category=some+simple+data+that+makes+your+url+inefficient
And a pretty one:
www.example.com/some-simple-data-that-makes-your-url-efficient-for-search-engines-s
In the last example your link has 24 characters more used for keywords in the same length the preview has.
How can we do this?Simple.
We will use forms with POST methos.This will send data via POST to a page where it will be redirected to a new location ,the URL rewrited.
<form method=”post>
<input name=”data” type=”text” >
<input type=”submit” >
</form>
The php script should contain on the firs line this:
if (isset($_POST['data']) && $_POST['data']!= ”) {
header( ‘Location: http://www.example.com/preg_replace(”/[^a-zA-Z0-9s ]/”, “-”, $_POST['data'])-s;
die();
}
and the .htaccess file should contain between the lines this(if you have an wordpress do not use this method)
RewriteRule ^([a-zA-Z0-9]+)-s$ redirected-page.php?data=$1
This is all.
Redirected-page.php is the page where you get the requests and show the results.