php - Clean URL for search results using htaccess

Wednesday, November 4, 2015

I have the URL: http://www.Test.lol/search.php?SearchParam=lodge&page-no=2 - I am trying to display it as just http://www.Test.lol/search/page-2/.



I build the link using: href=" <(?) php echo /search.php?SearchParam=" . $SearchParam . "&page-no=" . $page_no ?>">



When i navigate to page 2, I use GET to get the page number that I use as a limit in my MySQL statement. If I somehow manage to rewrite the URL, will that break the code that uses GET to get the page number?



When I try to rewrite the URL in htaccess, it displays it as above and does not seem to rewrite the URL:
RewriteRule ^search/$ /search.php?SearchParam=$1
RewriteRule ^search/page-([0-9]+)$ /search.php?SearchParam=$1&page-no=$2



When the search is submitted the first time, it uses a POST method. From there, i include the search param in the URL because when I navigate to pg 2, it loses the Search Param as POST.



Is there a specific line I need to use in my htaccess to rewrite the URL?



I should probably also say that I am very new to php so please have mercy. Thanks!

0 comments:

Post a Comment