Forum Moderators: phranque

Message Too Old, No Replies

301 redirect not precise enough

         

agneslesage

10:08 am on Sep 20, 2012 (gmt 0)

10+ Year Member



Hello
I have set this 301 redirect:
Redirect 301 /museum/departments http://www.mysite.com/museum/collections


The problem is, I want
the page '/museum/departments' to be redirected, but it seems soem engines think that also '/museum/departments/object' must be redirected and that creates kind of fake 404 errors on '/museum/collections/object' and it seems also problms for robots using my sitemap.

Did I do soemhting worng?
Should I add a slash (/) at the end or something?

Redirect 301 /museum/departments http://www.mysite.com/museum/collections/

phranque

11:39 am on Sep 20, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



you can use RedirectMatch to specify a regular expression and then you can end anchor the pattern.

agneslesage

12:05 pm on Sep 20, 2012 (gmt 0)

10+ Year Member



mmm...
I don't think I 'can' do that (due my limited skills!)
Would you specify?

Redirect 301 /museum/departments [mysite.com...]

phranque

12:12 pm on Sep 20, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



IMPORTANT: Please Use Example.com For Domain Names in Posts:
http://www.webmasterworld.com/apache/4452736.htm [webmasterworld.com]

Regex Tutorial - Start and End of String or Line Anchors:
http://www.regular-expressions.info/anchors.html [regular-expressions.info]

agneslesage

12:29 pm on Sep 20, 2012 (gmt 0)

10+ Year Member



So that would do
Rewriterule $departments [mysite.com...]

Is that right?
But that would not enable departments/ to be redirected...?

Again, I want

phranque

1:24 pm on Sep 20, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



IMPORTANT: Please Use Example.com For Domain Names in Posts - Apache Web Server forum at WebmasterWorld:
http://www.webmasterworld.com/apache/4452736.htm [webmasterworld.com]

agneslesage

1:32 pm on Sep 20, 2012 (gmt 0)

10+ Year Member



So that would do
Rewriterule $departments http://www.example.com/museum/collections/ 


Is that right?
But I am afraid that would also enable 'departments/' (with a slash at the end) to be redirected...?

Again, I want only URL ending with 'department' or 'department/'to be redirected, but not somethign like 'department/object/'

Thanks, and sorry for haing to correct

g1smd

6:43 pm on Sep 20, 2012 (gmt 0)

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



Use
^department/?$
as the rule pattern.

Make sure you add the
[R=301,L]
flags to force a 301 redirect (otherwise you get a 302).

lucy24

1:47 am on Sep 21, 2012 (gmt 0)

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



Is that right?

No. Anchors go in the place you are anchoring. If you want the text to begin with "abc" the anchor goes in front:

^abc

If you want the text to end with "xyz" the anchor goes at the end:

xyz$

Yes, both ^ and $ have other meanings in other areas of Regular Expression. They just do it to make your life a little more miserable.

agneslesage

8:32 am on Sep 21, 2012 (gmt 0)

10+ Year Member



Thanks,
So now I'll just test

Rewriterule ^department/?$ http://www.example.com/museum/collections/ [R=301,L]