简体   繁体   中英

SEO friendly html/ php form submission

I am looking to create an SEO friendly URL after a filter has been submitted in an html form.

After playing around for a while I have found a way, however I was wondering what otehr people think of it as I'm new to development.

I have added some rewrite rules in the .htaccess file to make the urls more friendly. Examples below:

Original URL: site-nane/list.php?brand=brand1&min-price=0&max-price=2000

URL after rewrite: site-name/section/brand1/0-200

Currently I have the form that submits the information to a separate php page which collects the variables and creates a new url from it which then redirects with a 301. Example of php below:

$min = $_GET[‘min-price’];
$max = $_GET[‘max-price’];
$brand = $_GET[‘brand’] ;

header ('HTTP/1.1 301 Moved Permanently');
header('Location: http://site-name/section/' . $brand . '/'. $min.'-'.$max );
exit();

As you can see it collects the info and takes you back to the page and declares the previous page has permanently moved.

Questions:

  1. Although this maybe quite primitive, will this still be ok to use without causing too much trouble?

  2. Will google hate me for creating so many 301's

  3. Just noticed the code header("Location: /foo.php",TRUE,301); would it be best to use this or no difference?

  1. Yes, I see no issues with your solution. Even if malicious user input was given it would just redirect to a non-existing page.

  2. I don't think so. You already use the right code 301 instead of the default 302 which might cause some trouble / did create some havoc with regard to Google, stolen PR and SEO

  3. Using header("Location:...", true, 301); is advisable. This way php could automatically make decisions based on the environment. Eg if using an HTTP/1.0 connection php could send the 301 code with HTTP/1.0 instead of your fixed HTTP/1.1 in your solution. But still, either way is fine.

But one question: why don't you link directly to your nice URL? mod_rewrite which you are using would then already take care of assigning the parameters given with the URL to variables that you could access via $_GET as usual.

The way you've done things is a permutation of the post redirect get (PRG) pattern. In your case, it's Get redirect get.

What PRG normally means is:

  • User POSTs the form to a controller which does whatever you want, and build the desired url
  • Script REDIRECTs use to the desired url
  • User GETs the url, sees the result.

Generally speaking, it's a good pattern to follow, it allows you the control to - eg - remove default values from the resultant search url.

Regarding your specific questions

  1. If it works, it's fine
  2. Google won't be submitting forms, so it won't be finding the pre-processed urls to get 301-redirected unless those urls exist somewhere else already. However, you need to be linking to "http://site-name/section/brand/min-max" for any search engine to know the pages exist.
  3. Either is fine, one line of code is easier to type though

Search engines do not submit forms.
Thus, no form action have to be friendly. (And,as another consequence - no, google won't hate you).

There is just no point in doing additional redirect instead of displaying form results.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM