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:
-
Although this maybe quite primitive, will this still be ok to use without causing too much trouble?
-
Will google hate me for creating so many 301’s
-
Just noticed the code header(“Location: /foo.php”,TRUE,301); would it be best to use this or no difference?
Yes, I see no issues with your solution. Even if malicious user input was given it would just redirect to a non-existing page.
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
Using header(“Location:…”, true, 301); is advisable. This way php could automatically make decisions based on the environment. E.g. 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.