Forum Moderators: phranque

Message Too Old, No Replies

2 Redirections Combined

Redirect both spiders and users

         

omoutop

12:23 pm on Feb 27, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi to all!

I need your wisdom guys.

I need 2 rules to redirect humans and spiders
something like this:

For users:
RedirectPermanent /crete/hotels/index.htm [mysite.com...]

For Robots-Spiders:
RewriteRule ^/crete/hotels/index.htm $http://www.mysite.com/crete/crete-hotels.htm [R=301,L]

Considerations:
1.Will the first rule work for both humans and spiders?
2.If not can these two rules above exist in the same file without any problems?

Thank you in advance!

jdMorgan

2:56 pm on Feb 27, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I see no difference in the function of these two redirects.

You will have better results with controlling interactions between two different redirects if you use either mod_alias or mod_rewrite, and not both. If you use both, you cannot explicitly control the order of execution of the directives for the two different Apache modules. That is determined by the LoadModule list on Apache 1.x, and by Apache 2.x's module priority scheme.

Mod_alias is simpler, mod_rewrite is more powerful. For example, mod_alias redirects unconditionally, while mod_rewrite has the RewriteCond directive that allows you to redirect based on user-agent, requesting IP address, etc.

Jim

omoutop

3:09 pm on Feb 27, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks again jd Morgan for your answer,

the problem here is that I need the first rule to redirect the user's browser window and the second rule to redirect robots. If i use only the first one and go to access page
[mysite.com...]
I am redirected automatically to
[mysite.com...]
But dont know if this is the same case for robots.

That is why i was wondring if I can use the second rule as well for the robots

If I use only the second rule
RewriteRule ^/crete/hotels/index.htm $http://www.mysite.com/crete/crete-hotels.htm [R=301,L]
and access [mysite.com...] my browser is not redirected and I get a page not found error.

It drives me crazy

jdMorgan

7:24 pm on Feb 27, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Both directives do exactly the same thing, as far as I can see.

Your mod_rewrite rule has a syntax error in it, but this may just be a typo from posting here. The "$" is misplaced. It should read:


RewriteRule ^/crete/hotels/index\.htm$ http://www.example.com/crete/crete-hotels.htm [R=301,L]

If this code is intended for use in .htaccess, as opposed to a server config file, then another change is needed; remove the leading slash from the pattern:

RewriteRule ^crete/hotels/index\.htm$ http://www.example.com/crete/crete-hotels.htm [R=301,L]

This applies to the example below as well.

It's also possible that you don't have any other working mod_rewrite rules in this file, in which case you need to add some "setup" directives for mod_rewrite.


Options +FollowSymLinks
RewriteEngine on
RewriteRule ^/crete/hotels/index\.htm$ http://www.example.com/crete/crete-hotels.htm [R=301,L]

Neither mod_alias nor mod_rewrite will distinguish between spiders and browsers, unless you add code to do that. Because both directives you show do the same thing, it looks like you don't need to add anything, though.

If you have a problem such as a 404-Not Found or a 500-Server Error, then go to your raw server error log file and see what the problem is. The error log file will often tell you exactly what the problem is, or at least show you the server filesystem path that the URL was translated to. This is often very useful information, and prevents the frustrating process of having us "help fix your problem by guessing" here.

Jim