Forum Moderators: phranque

Message Too Old, No Replies

htaccess 301 redirect doesn't work urgent help needed please

         

brakkar

9:19 pm on Nov 16, 2011 (gmt 0)

10+ Year Member



I'm setting htaccess 301 redirects for my entire site page by page. But it doesn't work well and I need urgent help please, here is an example of the line I have:

redirect 301 /pages/info [new...] domain.com/other/thing

doesn't redirect to [newdo...] main.com/other/thing but to [new...] domain.com/pages/info !

Why is this, and how can I have it work redirect to: [new...] domain.com/other/thing ?

Thanks !

g1smd

10:10 pm on Nov 16, 2011 (gmt 0)

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



Use RewriteRule for all of your rules. Use the [R=301,L] flags.

You'll have a lot more control over what happens.

brakkar

10:13 pm on Nov 16, 2011 (gmt 0)

10+ Year Member



Thanks. it was a problem of order : shorter links on top causing problem with specific pages

so /es would cause problem further down with /es/page

g1smd

10:36 pm on Nov 16, 2011 (gmt 0)

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



Single page rules go first.

More general rules go last.

Do not persevere with Redirect or RedirectMatch code.

Change the whole lot to use RewriteRule. It offers a lot more functionality.

lucy24

11:28 pm on Nov 16, 2011 (gmt 0)

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



And use example.com to keep the Forums from turning everything into clickable but unreadable links. We need to see what you typed, not go to your site. This applies to anything beginning in http:// --right down to a bare . as in [....] (I did that on purpose to illustrate).

brakkar

10:09 am on Nov 17, 2011 (gmt 0)

10+ Year Member



Thanks.
I have another issue where /de#kaufen doesn't redirect to http://www.example.com/other/page

Seems the special character # is causing an issue as /other/page from target is ignored.

g1smd

11:15 am on Nov 17, 2011 (gmt 0)

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



The # character represents an in-page link and the fragment is NOT sent to the server.

Everything after the # is resolved within the browser.

You can't use it for redirecting.

lucy24

11:52 am on Nov 17, 2011 (gmt 0)

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



Edit: Good grief. Didn't realize how slowly I type :)

Fragments aren't like query strings, which are handled in a specific way by mod_rewrite. Technically they're not even considered part of the URL.

If the Apache docs ever mention fragments, it's buried very deeply. But further exploration leads me to-- woo hoo!-- an entire forum devoted to mod_rewrite. O be still my thundering pulse.

[forum.modrewrite.com...]

The recurring theme-- I puttered around some other places too-- seems to be that the #fragment is never sent to the server in the first place; it's strictly for use by the browser. Which explains why Apache is silent.

So if your rewrite simply doesn't see the #fragment, that would be expected. But if it's doing something else, you have got me curious. Let's see an example of a rule that behaves differently when there's a fragment involved. Does the rule do nothing at all, or does it do something unexpected?