Forum Moderators: phranque

Message Too Old, No Replies

301 redirect help

         

bouncybunny

6:24 am on Apr 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member


Hi, I have been trying like crazy to redirect some old dynamic urls towards some new ones and all I get is 500 server errors, or redirects to the root page of the new site.

Here are a couple of samples of the redirect I am trying to make. I have a series of about 10 urls that I want to redirect to their new location, for example;

Redirect 301 /index.php?board=1.0 http://www.domain.com/community/forumdisplay.php?f=14

Redirect 301 /index.php?board=5.0 http://www.domain.com/community/forumdisplay.php?f=17

And I then want *all* other urls to simply go to the home page of the new directory. So I used this;

Redirect 301 /index.php http://www.domain.com/community/newpage.php

However, when I have this in place, the urls are referred to somewhere like;

http://www.domain.com/community/newpage.php?board=5.0

Which displays the home page OK, but that is not where I want to redirect to go and probably gets indexed by spiders about a thousand times, under different urls... :(

I've been at this for days and I can't work it out.

Can anyone please help me?

Thanks in advance.

bouncybunny

9:10 am on Apr 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Anyone?

Moby_Dim

6:23 pm on Apr 15, 2006 (gmt 0)

10+ Year Member



May be you need to use RedirectMatch and a regular expression - something like this :

RedirectMatch 301 \/index\.php.+$ http://www.example.com/community/newpage.php

[edited by: jdMorgan at 3:32 pm (utc) on April 16, 2006]
[edit reason] example.com [/edit]

bouncybunny

1:17 am on Apr 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks.

It just seems to ignore that unfortunately. Although I might well have implemented it wrongly. I'm pretty new at all of this.

jdMorgan

3:01 am on Apr 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A recent related thread [webmasterworld.com].

Jim

bouncybunny

4:14 am on Apr 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for that.

It's useful. Although, that's only a part of what I am trying to do.

The thing is is am trying to redirect about 10 specific urls to 10 other specific urls. For some reason the format that I showed in my first post will simply not redirect and I cannot work out why.

For any url that is not like those 10, I want them to go to a specific page within another directory.

bouncybunny

4:23 am on Apr 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member


I tried this

RedirectMatch 301 ^/index.php?board=1.0(.*)$ http://www.domain.com/community/forumdisplay.php?f=14

But it only directed it to;

http://www.domain.com/community/pagename.php?board=1.0

Also if I just use RedirectMatch 301 ^/index.php http://www.domain.com/community/pagename.php

Then it also has the same effect as above, it does redirect teh root page, but also the 10 other pages also go to the home page of the new site. So I end up with thousands of different links going to the same place.

jdMorgan

3:31 pm on Apr 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's probably time to dump the easy-to-use-but-limited mod_alias [httpd.apache.org] Redirect directives, and pull out the big guns. In other words, time for mod_rewrite [httpd.apache.org]. This module is far more powerful, but also harder to learn. And using it without undersanding it can be positively dangerous to your site, so please see the final paragraph below.

Assuming this code is for use in .htaccess, here's a Redirect 301 - RewriteRule equivalency example to get you started:

> Redirect 301 /index.php?board=1.0 http://www.example.com/community/forumdisplay.php?f=14

# Set=up: Enable mod_rewrite
Options +FollowSymLinks
# Set-up: Start rewrite engine
RewriteEngine on
#
# For each URL+query combination to be redirected to a unique new URL, add a two-line ruleset like this:
#
# If query starts with "board=1.0"
RewriteCond %{QUERY_STRING} ^board=1\.0
# Then redirect index.php to /community/forumdisplay.php with new query string
RewriteRule ^index\.php$ http://www.example.com/community/forumdisplay.php?f=14 [L]

For your application, you will need to create an additional two-line rule-set for each of your specifically-redirected URLs-plus-query strings, and then place a catch-all for all others at the end.

Do not try to mix mod_alias and mod_rewrite directives; They will not execute in the order you expect if you do this, because Apache executes all mod_alias directives and then it executes all mod_rewrite directives. In other words, the order of execution is by module first, and then by order in the .htaccess file.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim