Forum Moderators: phranque
I want it redirected to -
http://example.com/search.html?term=abcdefghijklmnop
I also have other urls in my htaccess, this shouldn't affect them.
I tried someways, but it ended in redirect loop & was stopped by the browser.
[edited by: jdMorgan at 3:26 pm (utc) on May 7, 2009]
[edit reason] example.com [/edit]
RewriteRule ^\(.*)$ [domain.com...]
When i tried accessing the site, it went into a loop & was stopped by the browser automatically.
So, several things to consider.
What you have there is a 302 redirect. It's a redirect (even though you didn't include the [R] flag) because you have included a domain name in the target.
To change it to a rewrite, omit the domain name from the target and add the [L] flag to the end of the rule. A rewrite does not contain a domain name because we are taking a URL as input and targeting an internal filepath as a result.
With a redirect, you are telling the browser to go fetch a new URL. That is not what you want here.
The \ in the pattern is incorrect and unwanted.
You may also need to add a RewriteCond before your rule, one that looks at THE_REQUEST so that the rewrite only fires off for direct client requests.
Your pattern of (.*) is too wide. It matches every request. That is, a request for /robots.txt will be rewritten to /search.html?term=robots.txt - and it is a fair bet that your script will not return the proper robots.txt file that Google and other search engines are looking for. You need a more restrictive pattern here, not one that matches 'everything'.
RewriteRule ^([^./]+)$ /search.html?term=$1 [L]
Or perhaps you'd like:
RewriteRule ^(([^/]+/)*[^.]+)$ /search.html?term=$1 [L]
In either case, the output cannot match the input and produce a loop, because neither of the rules' patterns will match if there is a period in the final path-part.
Jim