Tuesday 15 April 2014

.htaccess - php search form and url rewrite/formatting -


So I'm working on a self project myself and it is related to job search. I want to disclose the URL in this form: site.com/search/developer Where the developer keyword is clearly now it is that when I click on search (the submit button works) and the url form Appears in: site.com/search.php?kword=developerAnd I'm sure HTACAC rewrites can not change the way PHP behaves and how they format URLs.

Now I have an idea of ​​using Javascript so that when the user types a keyword, I'll take it and redirect the page via js to site.com/search/[keyword ] If this is a good idea (to look into disabled javascript cases)

What am I trying to achieve, this is a decent / recommended method, I know because there are some big websites, it is not only me who knows what is the best way to do it.

Thank you in advance.

You definitely make it to site.com/search/developer You can use Javascript for the very rare case when JavaScript becomes inactive, you can submit them to the regular URL form with the final URL as site.com/search.php?kword=developer You can.

The good news is that using mod_rewrite, you can always keep both cases in the browser for the URL.

Enable mod_rewrite and .htaccess via httpd.conf and then this code under your .htaccess under DOCUMENT_ROOT directory:

  option + follow link -Multi view #RedriteEdit on the redrawetbase #Mour Module Draft / #International ForwardCorrectCode% {REQUEST_FILENAME}! -f revised rule ^ search / (. ++) /? $ /search.php?kword=$1 [L, QSA, NC] # External rewrite rewrite% {THE_REQUEST} ^ [ed] {3,} \ s / + Search \ .php \? Kword = ([^ \ s] +) [NC] rewrite rule / search /% 1? [R = 302, L]   

Once you verify that this is working properly, then R = 302 to R = 301 . Avoid using R = 301 (permanent redirection) while testing your mod_rewrite rules.

No comments:

Post a Comment