homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

How to paste search result into html

 3:44 am on May 31, 2009 (gmt 0)

Hello guys,

Can anyone please tell me that if I have make a search page using GET and when anyone search in it the URL becomes


I want to do that when anybody search for any result then the URL becomes


and when search found more then 10 results then if person clicks on 2nd page then URL becomes


I also want to convert this into

(square bracket for syntax not included in text)

So please can anyone do this ... I will be thankful

And thanks to helpers in advance



 8:49 am on May 31, 2009 (gmt 0)

To make users 'see' and 'use' URLs like that, those URLs need to be in the links on your pages. It is links that define URLs.

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.


 11:31 am on May 31, 2009 (gmt 0)

From your suggestion I have made this query, it is working well and gives me results also but I dont know what this character is doing here can you please explain me and 2nd thing is this query is right?

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]


 11:47 am on May 31, 2009 (gmt 0)

It means "not a dot/period". Surely you need "not an ampersand" here?

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.


 11:53 am on May 31, 2009 (gmt 0)

Can you please tell me the necessary escaping so I can remove them from my query ... and then comment it


 12:23 pm on May 31, 2009 (gmt 0)

You only need to escape literal \. and \? in patterns here, and literal spaces. You never need to escape stuff in the target (stuff "on the right").

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]


 12:34 pm on May 31, 2009 (gmt 0)

RewriteCond %{QUERY_STRING} ^search=([^.]*)&submit=Click\+to\+search&submit=Click\+to\+search&page=([0-9*])
RewriteRule ^main/search.php$ [mysite.com...] [R=301,L]

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 ?


 12:39 pm on May 31, 2009 (gmt 0)

You need
^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]


 12:47 pm on May 31, 2009 (gmt 0)

I have remove all these errors and add escaping character where you told and also make my mistake right which you describe in the end..
Else i place ^main/search-([^-]*)-([0-9]*) instead of ^main/search-([^-]+)-([0-9]*)

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


 12:52 pm on May 31, 2009 (gmt 0)

"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. "

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

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved