Welcome to WebmasterWorld Guest from 107.20.75.63

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

redirect won't work

     
3:44 pm on Jun 14, 2012 (gmt 0)

Junior Member

joined:Apr 19, 2011
posts: 42
votes: 0


I have the following:

redirect 301 /events/my-events/ /event-categorie/our-events/
redirect 301 /event-categorie/event/ /events/

redirect 301 /events/evenementen/ /event-categorie/evenementen/
redirect 301 /evenementen/ /event-categorie/evenementen/


obviously that last rule will create an infinite loop with the rule before that. So I tried chnging it to:

redirect 301 http://mydomain.com/evenementen/ /event-categorie/evenementen/


But that doesn't work?
Can someone tell me what i am doing wrong please?
7:04 pm on June 14, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


Use RewriteRule syntax instead of Redirect.

The rule pattern should match the requested path and ONLY the requested path.

The rule target must include the protocol and domain name.

Finish by adding the [R=301,L] flags.

Are your rules for single URLs or for all pages within each of those folders?
7:29 pm on June 14, 2012 (gmt 0)

Junior Member

joined:Apr 19, 2011
posts: 42
votes: 0


Hi,

They are single URLs; it is a Wordpress site so those URLs are already the result of a rewrite. Because of the way a plugin works I need to redirect users from those 4 URLs (which are Wordpress pages) to the other 3 (which are plugin URLs). I could also use a meta refresh but I thought a rewrite would be better (considering both speed and the 301).
7:35 pm on June 14, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


Do you mean rewrite? Or redirect?
Those are two different actions with completely different outcomes.

Much confusion is caused by the fact that RewriteRule can be configured to deliver an external redirect or to perform an internal rewrite.

RewriteRule is much more powerful, so forget about Redirect and RedirectMatch completely.
7:43 pm on June 14, 2012 (gmt 0)

Junior Member

joined:Apr 19, 2011
posts: 42
votes: 0


Ok, I am confused, lol.

What I need is a redirect. I simply have 4 wordpress pages where, if a user lands on them I want them to (silently and immediatly) be taken to another page.

I changed my code to:

RewriteBase /
RewriteRule ^events/my-events/$ /event-categorie/our-events/? [L,R=301]
RewriteRule ^event-categorie/event/$ /events/? [L,R=301]
RewriteRule ^events/evenementen/$ /event-categorie/evenementen/? [L,R=301]
RewriteRule ^evenementen/$ /event-categorie/evenementen/? [L,R=301]


The first 3 work like a charm as before, the last one does not.
8:48 pm on June 14, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

joined:Apr 9, 2011
posts:12714
votes: 244


This is where you need to explain exactly what "does not work" means. If it helps, pretend you are explaining it to a stupid computer that does not understand anything ;)

:: brazenly stealing from jdMorgan ::

What about this code does not work? Does it do something wrong, not do anything at all, or what?

How did you test? What were the expected results? What were the actual results? How did the actual results differ from the expected results? Any error messages in the browser? Any relevant entries in the server error log? Did you completely flush (delete) your browser cache before testing?


Secondary points:

RewriteBase / is not needed, because it is the default.

In general, leave a blank line after each RewriteRule. Include # annotations (separate line!) explaining what each Rule is meant to do.

In the Target, give the complete protocol-plus-domain.

Luckily my first-guess explanation does not apply: Since everything is anchored, there is nothing in the first three patterns that would intercept the 4th pattern.

But, come to think of it: Rules 3 and 4 appear to be identical except for the leading "events/" directory. So why not collapse them into a single rule?

RewriteRule ^(events/)?evenementen/$ http://www.example.com/event-categorie/evenementen/? [L,R=301]
9:15 pm on June 14, 2012 (gmt 0)

New User

joined:June 15, 2011
posts: 14
votes: 0


RewriteRule ^evenementen$ /event-categorie/evenementen/? [L,R=301]
9:21 pm on June 14, 2012 (gmt 0)

Junior Member

joined:Apr 19, 2011
posts: 42
votes: 0


Hi,

"does not work" in this case means the 4th rule does not redirect, the link to /evenementen/ shows that page and not the /event-categorie/evenementen/ which I want to show.

Trying your combination of the 2 rules also only redirects /events/evenementen/ and not /evenementen/
Thanks for the feedback so far, I'll try again tomorrow.
10:11 pm on June 14, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


The rule target must include the protocol and domain name.


What other rules are in your htaccess file?

The four new rules should be very near the start of the file, certainly before your non-www to www redirect.

In turn, your internal rewrites for wordpress should be near the end of the file and certainly after all of the redirects.


Clear the browser cache before restesting. Additionally, use the Live HTTP Headers extension for Firefox to examine the HTTP headers.
10:16 pm on June 14, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

joined:Apr 9, 2011
posts:12714
votes: 244


There's got to be some earlier rule intercepting requests for /evenementen/ so by the time it reaches the RewriteRule, it's in a different form and the Rule can't touch it.

it is a Wordpress site so those URLs are already the result of a rewrite

Rewrite or redirect? A Rewrite doesn't change the URL; it can only change the source of the content.

Wordpress or not, the redirects (external) have to come before the rewrites (internal). If you have boilerplate htaccess that came with the Wordpress installation, there is probably a lot of extraneous stuff.

:: contemplating writing up another piece of boilerplate on "how to change your out-of-the-box htaccess into your own personal htaccess" ::


Tangential: I only recently (like, say, last week) figured out why people keep getting the "rewrite" concept backward. In a rewrite, you're creating a discontinuity between a page's visible name and the source of its content. Everyone gets that part. The part they get wrong is this: The name stays the same while the content source changes. Not the other way around.
10:23 pm on June 14, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


Yes, URLs are used "out there" on the web and filepaths are used "here" inside the server. They are not at all the same thing.

With mod_rewrite, everything happens after the click that generates a URL request sent to the server.

A redirect tells the browser to make a new request for a different URL.

A redirect maps a URL to a URL.

With a rewrite, the content is not fetched from the default path seen in the URL request. Instead the internal pointer is altered to instead fetch the content from a different place inside the server, without revealing what that internal location actually is.

A rewrite maps a URL to a filepath and file.
1:11 pm on June 15, 2012 (gmt 0)

Junior Member

joined:Apr 19, 2011
posts: 42
votes: 0


Sorry for the late response, I had some other work that had to be done before I could revisit this problem.

Thank you all for your input en time, I feel a bit stupid since moving the rules up to the very top of the file indeed resolved the problem. I did not take other (pre-existing) rules into account <blush>.
1:13 pm on June 15, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


It's a common mistake. Rule order is crucial.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members