Forum Moderators: phranque

Message Too Old, No Replies

.htaccess rewrite rule issue

         

username

12:42 am on Mar 27, 2009 (gmt 0)

10+ Year Member Top Contributors Of The Month



Hi all,

I am having difficulty structuring the correct RewriteRule to achieve what I want. Basically I have a year/month/day directory with folders in it i.e. [example...] I want my rule to redirect users who try to access [example...] for example, and at the levels, "2009", "03" also, but my rule just redirects everything below 2009 so far. The folders sitting beneath ../26/ all have index files in them (don' want redirected), and it is inneficient to redirect day folder manually using a script. How do I do this?

Thanks in advance.

g1smd

12:57 am on Mar 27, 2009 (gmt 0)

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



That should be quite easy. :)

What have you got so far?

You want to redirect people direct-accessing at three folder levels, but where do you want to direct them to?

username

1:08 am on Mar 27, 2009 (gmt 0)

10+ Year Member Top Contributors Of The Month



Hi g1smd, basically i just want to redirect them to the homepage or my 404 error page. I have:

RewriteEngine on
Redirect permanent /2009/ http://www.example.com

Unfortunately this does anything below 2009/... I want the 2009 (year) level, the 03 (month) level, and the 26 (day) level, but not the folders within the day level.

Thanks.

jdMorgan

1:18 am on Mar 27, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use RedirectMatch and a regex pattern to match /2009, /2009/, /2009/03, /2009/03/, /2009/03/26, or /2009/03/26/ -format URLs only:

RedirectMatch 301 ^2[0-9]{3}((/0[0-9]¦/1[012])(/[012][0-9]¦/3[01])?)?/?$ http://www.example.com/

Replace the broken pipe "¦" characters with soild pipes before use; Posting on this forum modifies the pipe characters. Note the trailing slash on the substitution URL.

Jim

g1smd

1:20 am on Mar 27, 2009 (gmt 0)

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



Redirecting large numbers of URLs to the root homepage is generally a bad idea.

You don't "redirect" people to a 404 page. The 404 page simply 'appears' for the current requested URL if that URL does not exist.

You won't be able to use Redirect here, as you'll need a certain amount of pattern matching to take place. Look at RewriteRule intead, but again, I wouldn't redirect these all back to the root index page.

username

1:27 am on Mar 27, 2009 (gmt 0)

10+ Year Member Top Contributors Of The Month



Hi Jim, the RedirectMatch, has had no effect. Direct access to the folders still shows a directory listing of sub folders even though there is no index. anything in the directory? I changed the broken pipes to pipes also?