Forum Moderators: phranque

Message Too Old, No Replies

Serve up a page in a sub-dir instead of the current one

Spent hours researching this, getting 500 server error

         

tigertom

1:12 am on Feb 13, 2007 (gmt 0)

10+ Year Member



## Serve subtly different pages to some bot
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^(.*botname.*¦.*otherbot.*)$ [NC]
RewriteRule ^(.*)\.shtml$ /archive/$1.shtml [PT,L]

I've tried umpteen variations of this, looked at loads of different tutorials, but keep getting a 500 server error that isn't showing up in the server error log.

So I don't know what's wrong.

jdMorgan

1:17 am on Feb 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If this code is in .htaccess, then you will need to explicitly prevent recursion:

RewriteCond %{HTTP_USER_AGENT} botname¦otherbot [NC]
RewriteCond $1 !^archive/
RewriteRule ^([^.]+\.shtml)$ /archive/$1 [PT,L]

If you have no previously-working rewrite rules, then you may need to enable mod_rewrite and turn on the rewrite engine as well.

Jim

tigertom

1:40 am on Feb 13, 2007 (gmt 0)

10+ Year Member



As usual, Jim, your code works a treat. Thanks very much.

I will try to figure out what was causing the error; perhaps the recursion, as other rewrite rules were working OK in that .htaccess file?

jdMorgan

2:55 am on Feb 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There was nothing to stop a rewritten request for /archive/file from being rewritten to /archive/archive/file, then to archive/archive/archive/file, ad infinitum...

Jim