Forum Moderators: phranque
Can anyone please tell me that if I have make a search page using GET and when anyone search in it the URL becomes
www.mysite.com/search.php?search=something&submit=Click+to+search&submit=Click+to+search
I want to do that when anybody search for any result then the URL becomes
www.mysite.com/search-searchtermhere.html
and when search found more then 10 results then if person clicks on 2nd page then URL becomes
www.mysite.com/search.php?search=something&submit=Search&page=2
I also want to convert this into
www.mysite.com/search-[searchtermhere]-[pageno].html
(square bracket for syntax not included in text)
So please can anyone do this ... I will be thankful
And thanks to helpers in advance
Once you have the user requesting the URL in the right format, use a rewrite to connect that request to the dynamic parameter-based filename that exists inside the server.
RewriteRule ^search-searchterm /search.php?search=something&submit=Search [L] Take this opportunity to "go extensionless" too. It often makes the pattern-matching in your rule much easier.
1. ([^.]*) in this part what is work of ^. here
2. Please can tell me that my query is right or want some improvement
RewriteRule ^main/search\-(.*)-([0-9])$ /Copy-of-New-Fun/main/search\.php\?search\=$1\&submit\=submit\&page\=$2 [L]
RewriteCond %{QUERY_STRING} ^search=([^.]*)\&submit\=Click\+to\+search\&submit\=Click\+to\+search\&page\=([0-9])
RewriteRule ^main/search\.php$ /Copy-of-New-Fun/main/search\-%1-%2? [R=302,L]
Most of the escaping you have added is unnecessary.
Are you sure you want a 302 redirect, and not a 301 redirect instead?
With a redirect you should include the full domain name in the target URL.
List the redirect before the rewrite.
The .* pattern should be replaced with "not a hyphen" code.
Your page numbering allows only for a single digit.
Clean that lot up and post again...
COMMENT your code to explain what each block does.
Documentation like [httpd.apache.org...] might prove helpful in your learning of Mod_Rewrite too.
[edited by: g1smd at 12:35 pm (utc) on May 31, 2009]
RewriteRule ^main/search-([^-]*)-([0-9]*)$ /Copy-of-New-Fun/main/search.php?search=$1&submit=submit&page=$2 [L]
I check my query after clearing the points you mentioned above then now query is working good and I think now all of unnecessary escaping is removed can you please check it again and tell me mistake if there are some ?
^main/search.php$ to be changed to ^main/search[b]\.[/b]php$ here. Note that in
^main/search-([^-]*)-([0-9]*) you will match zero or more times. That allows the variable to be blank. I think you instead will need ^main/search-([^-][b]+[/b])-([0-9][b]+[/b]) here. The + matches one or more times. Likewise
([0-9*[b]][/b]) is a typo for ([0-9][b]+[/b]) I think. Why is the "submit" parameter repeated in your pattern? Remove one instance of that.
Make sure that you COMMENT your code.
Additionally, add one of the common "site-wide non-www to www redirects" after your existing redirect and before the rewrite.
[edited by: g1smd at 12:47 pm (utc) on May 31, 2009]
because if user type nothing and press search button so it will find an error that "Please! enter search term" ..... that's y ... so is this right ?
And thanks in advance for your help and for giving your precious time to me ... Very thankful to you
Additionally, add one of the common "site-wide non-www to www redirects" after your existing redirect and before the rewrite. "
Can you please describe what are you trying to tell me , I can not understand it clearly
and this "submit" parameter repeated becz one is for form field which is shown to user and other is for hidden field, becz page giving error in IE to display the search result when press enter key without including this hidden field