Forum Moderators: phranque

Message Too Old, No Replies

Need Help with strange mod rewrite and 301 to other domain

         

DandyD

8:42 pm on Nov 22, 2011 (gmt 0)

10+ Year Member



Hello,

I have a problem with mod_rewrite and 301 forwarding.

My situation is that I want to move innerpage URLs from my old domain to my new domain with 301 forwarding.

The URLs for my old domain are rewritten already. URLs like details?link_id=xx are rewritten to details-xx.html

Now I want to 301 one of these inner pages to a specific URL on the new domain.

I added this line to my old domain:
Redirect permanent /details-xx.html [test.com...]

The redirect works BUT on the new domain the query string of the old URL is shown suddenly.

[test.com...]

How can I stop to show the query string. Otherwise I'm not sure if all the link juice will be passed to the correct URL when this query string appears.

Anybody an idea perhaps?

g1smd

9:28 pm on Nov 22, 2011 (gmt 0)

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



Use RewriteRule for all of your rules.

This can be configured to remove query strings in the redirect.

DandyD

10:14 pm on Nov 22, 2011 (gmt 0)

10+ Year Member



Thanks for the answer. The problem is that I spent hours already and can't find a correct solution.

Currently I'm using these statements for my old domain:
RewriteEngine On
RewriteBase /
RewriteRule ^details-([0-9]+).html$ details.php?link_id=$1

Redirect /details-14307.html [newdomain.com...]

As I mentioned already with the redirect I see this URL: [newdomain.com...]
There I would like to remove the query string completely.

Do you have any further advice perhaps?

g1smd

10:43 pm on Nov 22, 2011 (gmt 0)

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



I have posted how to remove query strings at least three times so far this week and there's a boiler-plate posting by lucy24 that gets rolled out almost every day in this forum.

In Google [site:webmasterworld.com RewriteRule remove query string] will find the details.

Stop using Redirect. Use RewriteRule instead.

Add the [L] flag to your existing RewriteRule.

List all of the redirecting RewriteRules before any of the rewriting RewriteRules.

Use example.com in this forum to stop URL auto-linking.

With that, the pub calls. I'm supposedly on holiday...

lucy24

11:47 pm on Nov 22, 2011 (gmt 0)

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



You can't have an internal rewrite followed by an external redirect. Well, technically maybe you can, but you will be sorry.

Throw out the old rewrite. What you need to do now is first redirect from the old domain-- using whatever form of URL people are asking for-- to the new domain-- ending up with the URL you want people to see. And then, within the new domain, rewrite to the location that will really be serving the content.

That's assuming the material actually lives in the new domain. Otherwise you've got icky messy business involving proxies, and I'm not going there.

DandyD

7:06 am on Nov 23, 2011 (gmt 0)

10+ Year Member



Thanks a lot again for the answers. The problem is that I'm not that technical and until now I only used complete rules which worked for my pages but my current problem seems to be much harder for me. :)

What I understood is that I shouldn't use Redirect statement - ok.

lucy said that I can't use internal rewrite followed by an external redirect. This being said would mean that I have to update old domain and domain htaccess.

The problem for me now is - do I lose my link juice then? I thought that I have to use the rewritten URI from the old domain and that I can't use the old structure described in the first rewrite rule.

g1smd, thanks for the search string for google but I already read different topics here but still wasn't successfull with any change.

So, just to be clear. I have to change something on my old domain AND my new domain. Correct?

lucy24

7:44 am on Nov 23, 2011 (gmt 0)

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



Yes. Basically, you're making the new domain do everything the old domain used to do. Rewriting between domains is perilous. I'm not touching it ;)

Straight redirects are not generally a problem with google. Some people report a temporary downward hiccup, but then things get back to normal. It sounds as if what you're doing is spinning-off one part of your old domain to a separate domain? Much depends on whether your original domain was perceived as a unified whole, so if you break it up, you have to start all over again. But you're the best judge of that.

If you have links to the moved pages, it will probably help if you can get the people at the other end to update the links to reflect the new location. Or at least some of them. Of course the new domain has to be "live" before you do this, so they know you're not just some competing party trying to hijack links :)

It is generally safer not to combine mod_rewrite (RewriteRule, which can optionally be used to redirect) and mod_alias (Redirect by that name) in the same htaccess. Or possibly even the same domain. Even if, ahem, Apache says sometimes you don't need mod_rewrite. The practical reason-- especially if you don't speak fluent Apache-- is that if everything is done with the same module, you can be absolutely certain that things will happen in the order you want.

DandyD

8:02 am on Nov 23, 2011 (gmt 0)

10+ Year Member



Yes, I want to push my new domain with content from my old domain.

So in the end I think that I need to redirect each single post from the old domain to a user friendly URL on the new domain.

My example now would be:

Old domain:
RewriteRule ^details-([0-9]+).html$ details.php?link_id=$1
Redirect Permanent /details-14307.html http://example.com/tiger
Redirect Permanent /details-14308.html http://example.com/monkey
Redirect Permanent /details-14309.html http://example.com/elephant

New domain:
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^?\ ]*\?[^\ ]*\ HTTP/ [NC]
RewriteRule (.*) http://example.com/$1? [R=301,L]

Might this be correct then? Sorry, I'm really kind of helpless here. :/

g1smd

8:15 am on Nov 23, 2011 (gmt 0)

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



Stop using Redirect. Use RewriteRule instead.

DandyD

8:28 am on Nov 23, 2011 (gmt 0)

10+ Year Member



Ah ok sorry - you said it already.

Replacing
Redirect Permanent /details-14307.html http://example.com/tiger

with
RewriteRule ^details-14307.html$ http://example.com/tiger? [R=301,L]

DandyD

4:06 pm on Nov 23, 2011 (gmt 0)

10+ Year Member



OK - now I got this working...

Old Domain:
RewriteCond %{QUERY_STRING} ^link_id=3
RewriteRule ^ [lootseller.de...] [QSA,R=301,L]

New Domain:
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^?\ ]*\?[^\ ]*\ HTTP/ [NC]
RewriteRule (.*) http://www.example.com/$1? [R=301,L]

I hope this is OK. Now I have write down two lines on the old domain per page because it's always another target - round about 300 I would guess. :)

Thanks for your help. If there's anything I can optimize please let me know.

lucy24

8:49 pm on Nov 23, 2011 (gmt 0)

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



Urk. If you speak php, you don't need to dump it all in htaccess. Rewrite everything to a script that looks things up:

link_id=1 >> cat
link_id=2 >> dog

et cetera. The script winds up by redirecting to the desired page in the new domain.

If you're only doing this one time to facilitate site migration, it may take less time to put it all in htaccess than to learn php ;) Your call.