homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

redirect won't work

 3:44 pm on Jun 14, 2012 (gmt 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 Jun 14, 2012 (gmt 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 Jun 14, 2012 (gmt 0)


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 Jun 14, 2012 (gmt 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 Jun 14, 2012 (gmt 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 Jun 14, 2012 (gmt 0)

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 Jun 14, 2012 (gmt 0)

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


 9:21 pm on Jun 14, 2012 (gmt 0)


"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 Jun 14, 2012 (gmt 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 Jun 14, 2012 (gmt 0)

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 Jun 14, 2012 (gmt 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 Jun 15, 2012 (gmt 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 Jun 15, 2012 (gmt 0)

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

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved