Forum Moderators: phranque

Message Too Old, No Replies

Seemingly simple rewrite mod has me baffled

         

weela

1:22 pm on May 23, 2005 (gmt 0)

10+ Year Member



Hello,

Firstly let me apologize for such a noobish question, but I’m at wits end here. I have a journal type site where the majority of my files are held in one folder. So not surprisingly www.site.com/folder/ for whatever reason gets a bunch of hits and some PR as well. I want to redirect any landings that fall on www.site.com/folder to www.site.com/ .

However I want to make sure I’m doing it in as SEO friendly way as possible, i.e users still have to be able to access files (images/pages) in that folder but there is no need for them to see www.site.com/folder/ itself, in my estimation as all navigation is done form the main page.

I’ve tried various rewrites and redirects but none of them seem to do what I’m after, I’ve tried searching for the answer and I get close, but the others who have gotten guidance always seem to be asking for something a little different, than my seemingly simple problem. I tried the apache documentation as well, but it reads like greek to me.

Any help would be greatly appreciated

sitz

3:48 pm on May 23, 2005 (gmt 0)

10+ Year Member



You need to create a mod_rewrite rule which won't get called if the requested URL is in an exclusion list:

RewriteEngine on
RewriteCond %{REQUEST_URI}!^/folder/images/
RewriteCond %{REQUEST_URI}!^/folder/do_not_redir_this/
RewriteCond %{REQUEST_URI}!^/folder/another/path/to/not/redirect
RewriteCond %{REQUEST_URI} ^/folder/do/not/redirect/this/file.html$
RewriteRule ^/folder/(.*) /$1 [L,R=301]

Untested, but ought to do more or less what you need (assuming I understand the question).

weela

4:29 pm on May 23, 2005 (gmt 0)

10+ Year Member



Sitz,

Thanks much for the reply. So I understand this, if you could please explain which part of that tells any direct requests for site.com/folder/ to just go to www.site.com

I don’t really see that, although that might be very indicative of the whole problem, I just don’t get rewrites very well.

Thanks for your response.

sitz

6:13 pm on May 23, 2005 (gmt 0)

10+ Year Member



Any request which is prefixed with /folder/ will get rewritten UNLESS the path is excluded via one of the RewriteCond lines. The actual Rewrite is handled by the RewriteRule; RewriteCond lines don't take any direct action, they only influence the RewriteRule they precede.

Note that you'll need to place a space between %{REQUEST_URL} and the '!' character in all the RewriteCond lines, or you'll get an Internal Server Error (error 500)