Forum Moderators: phranque

Message Too Old, No Replies

Problems with redirecting using mod rewrite

Newbie when it comes to .htaccess

         

wide_circle

8:16 pm on Apr 25, 2007 (gmt 0)

10+ Year Member



I would like to use .htaccess for redirects.
Have some questions though...
I've got it to work when the redirect's "section" looks like this:

RewriteRule ^sida1\.html$ index.html [R,NE,L]

RewriteRule ^sida1\.html$ index.html [R,NE,L]

RewriteRule ^sida2\.html$ index.html [R,NE,L]

RewriteRule ^sida3\.html$ index.html [R,NE,L]

The problem is that the first line (which could be any of the other redirects as well) needs to be there for it to work otherwise the RewriteRule ^sida1\.html$ index.html stops working - why is that - there is something that I'm missing here...

Also I would like these redirects to happen ONLY when the site is visited by browsers and NOT redirect when a search engine bot is crawling the site.
How would I go about doing that?
Would this work:

# Detects the major search engines
RewriteCond %{HTTP_USER_AGENT}!Googlebot¦Msnbot¦Slurp¦Jeeves [NC]

Thanks - would appreciate some help...

jdMorgan

8:54 pm on Apr 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Does this work?

RewriteRule ^sida1\.html$ http://www.example.com/index.html [R=301,L]
RewriteRule ^sida2\.html$ http://www.example.com/index.html [R=301,L]
RewriteRule ^sida3\.html$ http://www.example.com/index.html [R=301,L]

The main difference is that an external redirect should specify the protocol and domain, otherwise, the domain specified by ServerName may be used if UseCanonicalName is set to "On".

Jim

wide_circle

7:15 am on Apr 26, 2007 (gmt 0)

10+ Year Member



Hi Jim!

Thanks for your reply - it doesn't work. Still the same problem - with your code the 1st. line stops working again.
I'm not quite shure what you are talking about at the end of your reply though. The canonical etc. :-)

Niklas

wide_circle

7:54 am on Apr 26, 2007 (gmt 0)

10+ Year Member



Got it to work.
The excludes caused the problem. If
#RewriteCond %{REQUEST_FILENAME} !-f is not in use it's working - not sure why though... :-)

# Enables mod_rewrite
RewriteEngine on

# Sets the base folder of the Flash content
RewriteBase /

# Excludes real files and folders from rewriting
#RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Redirects
RewriteRule ^sida1\.html$ index.html [R,NE,L]
RewriteRule ^sida2\.html$ index.html [R,NE,L]
RewriteRule ^sida3\.html$ index.html [R,NE,L]

g1smd

1:11 am on Apr 28, 2007 (gmt 0)

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



>> I would like these redirects to happen ONLY when the site is visited by browsers and NOT redirect when a search engine bot is crawling the site. <<

Cough. I would read up on what Matt Cutts has to say about such redirects before your site falls down some massive Google-generated anti-web-spam hole that might open up beeath it.