Forum Moderators: phranque
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.
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.
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.
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