So I have a search box with GET , the browser then redirects to search.php?q=search_query , where search_query is the search you make . I've also made SEO Friendly url's like search/search_query.html but those work only if you type them . How can I make so the PHP code will auttomatically direct me to search/search_query.html ?
if(isset($_GET["q"])) { header("Location: http://yourwebsitename/search/".$_GET["q"].".html"); } PHP: At the top of the page, before any HTML is outputted.
hey, I inserted the code in search.php and says the next message : I think I must put the code in other php file ( search1.php ) and set the input form to search1.php and the redirects to search.php ( without that in the header ) .
Actually, that would be a 301 (permanently moved) header, and you don't need to do it here, because Google doesn't submit forms. If it is intended to link to the search queries using the ?q= protocol, sending a 301 would be a good idea, however. I would have to see more about your system and code to know for sure. It depends on how your URLs are being rewritten I think. Have you solved this by now?
I suggest you to use Apache redirects instead of php redirects. That saves a lot of load on your server.
If you are not creating static html files ( depending on search results ), easier will be to do this from .htaccess ( domain.com/search-term actually points to domain.com/search.php?key=search-term ).
@wayfarer : didn't resolved it , but I don't want to create another php file and redirect from one to another ... @adstiger : that sounds a little hard since I have a shared hosting ... @ActiveFrost : my htaccess looks like this : RewriteEngine On RewriteRule ^search/([^/]*)\.html$ /search.php?q=$1 [L] Code (markup): It works if you type the url ... I remember there was another code to redirect from htaccess ( from search.php to search/query.html ...