Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I searching for a redirection code for my url:

what I want is when some one search in my site it should redirect

example: if some one search google.com on mysite

then in address line it should look like www.mydomain.com/google.com

can be in $_POST method or $_GET

how do I do that??

share|improve this question

1 Answer 1

RewriteEngine On
RewriteCond %{HTTP_REFERER} google\.com
RewriteRule ^.*$ http://www.mydomain.com/google.com [R,L]

in an .htaccess file might work, i have not tested it.

you could try:

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /(.*)\/search\.php\?q=(www\.)?([^/\ ]+)[^\ ]*\ HTTP/
RewriteRule ^.*$ http://www.mydomain.com/%1 [R,L]

this link also has some other example 'smart' .htaccess rules: http://www.askapache.com/htaccess/http-https-rewriterule-redirect.html

share|improve this answer
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /search\.php\?q=(www\.)?([^/\ ]+)[^\ ]*\ HTTP/ this is for request of any kind of search domains..but what I dont know is how do I convert to mydomain.com/domain.com –  mathew May 19 '10 at 8:47
added another potential answer –  cpbills May 19 '10 at 8:57
nop it doesnt work –  mathew May 19 '10 at 9:39
does it do /anything/ can you provide more information as to how it doesn't help? maybe enable logging for RewriteRules RewriteLog file-path and RewriteLogLevel 9 httpd.apache.org/docs/2.0/mod/mod_rewrite.html you also have to be willing to play with the regular expression in the RewriteCond to see if you can at least get it to trigger. i don't know where you got that pattern, so i have no idea if it should work or not, you provided it. –  cpbills May 19 '10 at 16:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.