Forum Moderators: phranque

Message Too Old, No Replies

rewrite rule causing 403 error

rewrite rule causing 403 error

         

greenone

12:41 pm on Oct 15, 2009 (gmt 0)

10+ Year Member



Hello,

I have a problem with htaccess. Hoping someone here could help me solve it, I describe here the scenario.

1. I want to redirect specific mobile user-agents to mobile top page.
2. I want to redirect normal users and crawlers from the mobile site to the normal pc site.

I have the following in my .htaccess file.

Options +FollowSymlinks
RewriteEngine On

### Redirect PC domain to mobile domain according to user-agent with exemption
RewriteCond %{HTTP_HOST} ^(www\.)?example\.co\.jp [NC]
RewriteCond %{REQUEST_URI} !^(/m/?).*$ [NC]
RewriteCond %{HTTP_USER_AGENT} "DoCoMo¦KDDI¦J-PHONE¦Vodafone¦SoftBank¦UP\.Browser¦MOT" [NC]
RewriteRule ^(.*)$ http://www.example.co.jp/m/index.html [R=301,L]

### If /m/~ is requested by other user agents than the ones below, redirect to top page
RewriteCond %{REQUEST_URI} ^(/m/?).*$ [NC]
RewriteCond %{HTTP_USER_AGENT} !"DoCoMo¦KDDI¦J-PHONE¦Vodafone¦SoftBank¦UP\.Browser¦MOT" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} !"Y!J-SRD¦Y!J-MBS¦Googlebot-Mobile¦ichiro/mobile¦LD_mobile_bot¦symphonybot1\.froute\.jp" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} !"SNVSE00000001¦i-robot¦KDDI-Googlebot-Mobile¦MSNBOT-MOBILE¦BaiduMobaider¦Google-Sitemaps" [NC]
RewriteRule ^(.*)$ http://www.example.co.jp/ [R=301,L]

Everything under /m/ directory corresponds to mobile site.
The above code seems to work fine on my test server but when I upload the code to my production server, it trows a 403 error when accessing the site from one of the User-agents specified in the rules (Vodafone for example).

My test server is Apache/2.2.3 (Red Hat)
My production serer is Apache/1.3.27 (Unix)

I someone could help me, would be very much appreciated. I'm trying to find out if something in my rules is not compatible with apache 1.3.x

Thanks.

jdMorgan

1:43 pm on Oct 15, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A 403-Forbidden error?

That's a problem with something in the /m/ filepath, then, and not something having to do with the rules themselves.

Look at your server error log. It may be quite useful.

I have some comments about your code, but none of the things I see are 'fatal' problems.

Jim

greenone

10:36 am on Oct 16, 2009 (gmt 0)

10+ Year Member



Thanks for your answer jdMorgan!

I will come back with the findings I can make from the error logs.

Green