Forum Moderators: phranque
#sphider rewrite
RewriteEngine on
RewriteCond %{QUERY_STRING} ^query=(.*)\&type=(.*)\&results\=(.*)\&search=1$
RewriteRule ^search\.php$ /search/%2/%3/%1\.html? [R=301,L]
#Did you mean fix
RewriteCond %{QUERY_STRING} ^query=(.*)\&search=1$
RewriteRule ^search/(and¦or¦phrase)/[0-9]{2}/search\.php$ /search/and/10/%1\.html? [R=301,L]
#More results fix
RewriteCond %{QUERY_STRING} ^query=(.*)\&search=1\&results=(.*)&domain=(.*)
RewriteRule ^search/(and¦or¦phrase)/[0-9]{2}/search\.php$ /domain/%2/%3/%1\.html? [R=301,L]
RewriteRule ^domain/(.*)/(.*)/(.*)\.html /search\.php\?query=$3&results=$1&domain=$2&search=1&do=1 [L]
#Redirect main search
RewriteRule ^search/(.*)/(.*)/(.*)\.html /search\.php\?query=$3\&type=$1&results=$2&search=1&do=1 [L]
#Redirect sphider's logo
RewriteRule ^search/(and¦or¦phrase)/[0-9]{2}/(.*)\.png$ htttp://www.throughowleyes.com/$2.png [L]
RewriteRule ^domain/[0-9]{2}/(.*)/(.*)\.png$ htttp://www.throughowleyes.com/$2.png [L]
#Redirect the complete Suggest framework
RewriteRule ^search/(and¦or¦phrase)/[0-9]{2}/include/(.*)$ htttp://www.throughowleyes.com/include/$2 [L]
RewriteRule ^domain/[0-9]{2}/(.*)/include/(.*)$ htttp://www.throughowleyes.com/include/$2 [L]
#Redirect css files
RewriteRule ^search/(and¦or¦phrase)/[0-9]{2}/(.*)\.css$ htttp://www.throughowleyes.com/$2.css [L]
RewriteRule ^domain/[0-9]{2}/(.*)/templates/(.*)\.css$ htttp://www.throughowleyes.com/templates/$2.css [L]
how would i test that my hosting support and¦or¦phrase or not?
Thanks
Mahabub
[edited by: Mahabub at 7:44 am (utc) on Dec. 7, 2008]
(.*) patterns need to be replaced with something like ([^/]+) or ([^.]+) because using (.*) is usually very very inefficient. The rules that are 301 redirects (first three) need to state http and the full domain name in the target URL, otherwise you might run into duplicate content issues.
The rest of the rules say "redirect" in the comments, but each of those is actually a "rewrite" which is something different. Change the comment to say "rewrite".
You may also have a major problem in that you are externally redirecting dynamic URLs to static URLs, and then internally rewriting those static URLs to dynamic filepaths. This causes an 'infinite loop'. The solution is to check to be sure that the client (browser or robot) directly requested the dynamic URL before redirecting it to the static URL, by testing THE_REQUEST in a RewriteCond as shown. This prevents a dynamic URL resulting from an internal rewrite from being redirected back to its static form, rewritten back to dynamic, redirected again, rewritten again, etc.
Example:
# More results fix
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /search(or¦phrase)/[0-9]{2}/search\.php\?query=([^&]+)&search=1&results=([^&]+)&domain=([^&]+)
RewriteRule ^search/(or¦phrase)/[0-9]{2}/search\.php$ /domain/%3/%4/%2\.html? [R=301,L]
#
RewriteRule ^domain/([^/]+)/([^/]+)/([^.]+)\.html /search\.php\?query=$3&results=$1&domain=$2&search=1&do=1 [L]
I removed the escaping on the "&" characters, since it is not necessary. Note also that the escaping rules are different within alternate character [groups].
Note that I also changed your "and¦or¦phrase" to "or¦phrase" for technical terminology correctness only -- The "¦" means "OR", so if you want an "AND" function, then you need to do that with multiple RewriteConds.
Replace all broken pipe "¦" characters with a solid pipe character before use; Posting on this forum modifies the pipe characters, and patterns with broken pipes in them will not work as expected.
Jim
We don't do that here -- There is simply too much demand, and not enough contributors here to support that kind of 'free coding service'. Our purpose is to educate, rather than to provide a "help desk."
We'll be quite happy to help you learn to modify your code and get it working, but it is just that: Your code.
It is also a good idea to be sure that you completely understand any code you put on your server. Be aware that this is server-configuration code; Any single typo or minor error can have potentially-devastating effects on your server's performance and/or your pages' rankings in search engine results. If you do not understand the code and all of its effects on your server and page rankings, then you would truly be better off not using the code.
Please read the Apache Forum Charter [webmasterworld.com], which contains information about how to get the most from this forum, and links to some very useful resources. Also see our Apache Forum Library [webmasterworld.com], which contains several tutorials and other useful threads. Then post specific questions in this thread.
Note that I gave you a working example for one of your most-complex rules. You should be able to 'infer' many or all of the changes needed to the simpler rules by looking at the changes made to that complex rule.
Thanks,
Jim
Whats wrong with the below code:
Options FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^query=([^/]+)\&search=1$
RewriteRule ^search\.php$ [domain.com...] [R=301,L]
RewriteRule ^/search/([^/]+)\.html search.php?query=$1&search=1$
Also I try the below one and its cause an unlimited loop how would i stop this.
Options FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^query=([^/]+)\&search=1$
RewriteRule ^search\.php$ [domain.info...] [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^search/([^.]+)\.html$ /search.php?query=$1&search=1 [L]
Thanks
Mahabub
[edited by: Mahabub at 7:46 am (utc) on Dec. 14, 2008]
the code which i post cause an infinite loop I just want to know how can i avoid that i need some help really its urgent. Again i post the code...
Options FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^query=([^/]+)\&search=1$
RewriteRule ^search\.php$ [domain.info...] [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^search/([^.]+)\.html$ /search.php?query=$1&search=1 [L]
Thanks
Mahabub
To fix it, you need to check to be sure that the "search.php" URL is being requested directly by the client, and not as a result of the search/x/html URL being rewritten to the search.php URL. To do that, change the first rule:
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /search\.php\?query=([^&]+)&search=1\ HTTP/
RewriteRule ^search\.php$ http://www.example.com/search/%1\.html? [R=301,L]
Jim