Allowing only specific directories

Using mod_rewrite to handle various content issues

Allowing only specific directories

Postby visualsense » Mon Sep 08, 2008 1:35 pm

Hello,

I have a site with 4 different languages.

Somehow I keep getting weird 404's, most probably by bots.

What I would like to do is to redirect everything that doesn't have one of the for languages codes:

Allowed should be:

www.mysite.com/en/etc/etc/
www.mysite.com/nl/etc/

Redirected to root should be anything without "en" or "nl" as the first dir.

www.mysite.com/disallowed/etc/etc/

Hope you understand what I try to explain here and can help me with the solution.

Thank you,

Giorgio
visualsense
 
Posts: 16
Joined: Thu May 31, 2007 11:06 pm

Postby richardk » Wed Sep 10, 2008 9:59 am

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule !^(en|nl)(/.*)?$ /? [R=301,L]

! means "not".
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby visualsense » Thu Sep 11, 2008 3:17 am

Hi Richard,

That didn't work.
I get a continuing loop when accessing the root, ie www.mysite.com

Also tried the following:

RewriteRule ^!(en|nl|it|de)(.*)?$ http://www.mysite.com/en/ [NC,R=301,L]

as well as:

RewriteRule !^(en|nl|it|de)(.*)?$ http://www.mysite.com/en/ [NC,R=301,L]

Any idea?

Thx,

Giorgio
visualsense
 
Posts: 16
Joined: Thu May 31, 2007 11:06 pm

Postby richardk » Thu Sep 11, 2008 1:48 pm

Oops. It should also ignore /. Try
Code: Select all
!^((en|de|it|nl)(/.*)?)?$

instead of
Code: Select all
!^(en|nl)(/.*)?$


Edit: If you still have problems, post your full mod_rewrite.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby visualsense » Fri Sep 12, 2008 12:49 am

So I implemented the rule just like you said, ie:

Code: Select all
RewriteRule !^((en|de|it|nl)(/.*)?)?$ http://www.mysite.com/en/ [NC,R=301,L]


I still get a loop and ends like this:

Code: Select all
http://www.mysite.com/en/?a=en


What I did is request the site with an approved URL, ie:

Code: Select all
http://www.mysite.com/en/
visualsense
 
Posts: 16
Joined: Thu May 31, 2007 11:06 pm

Postby richardk » Fri Sep 12, 2008 2:06 pm

Post your full mod_rewrite.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby visualsense » Sat Sep 13, 2008 11:19 pm

This is the one:

Code: Select all
RewriteRule !^((en|de|it|nl)(/.*)?)?$ http://www.mysite.com/en/ [NC,R=301,L]


Isn't that what you meant?
visualsense
 
Posts: 16
Joined: Thu May 31, 2007 11:06 pm

Postby richardk » Mon Sep 15, 2008 10:44 am

I meant all the other rules you have.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby visualsense » Tue Sep 16, 2008 5:31 am

Hi Richard,

It's quite a big file :) I have 301 redirect basically all changes (new named pages, expired content etc) in the past two years, but the one we're talking about was placed on top.

If you really need it I prefer to send it in a PM instead of posting it here, would you mind?

Kind regards,

Giorgio
visualsense
 
Posts: 16
Joined: Thu May 31, 2007 11:06 pm

Postby richardk » Tue Sep 16, 2008 12:11 pm

PM me then. The problem is the order of some of the rules (redirects first) and/or missing L flags (all redirects must have an L flag, probably all rules).
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Next

Return to Content

Who is online

Users browsing this forum: No registered users and 6 guests

cron