Welcome to WebmasterWorld Guest from 54.144.243.34

Forum Moderators: Ocean10000 & incrediBILL & phranque

How to redirect forum urls to a single page?

redirecting multiple urls to a single page

   
5:58 pm on Jan 17, 2013 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, it has certainly been awhile since I posted at my old haunt. :)


I am a .htaccess butcher and while in the midst of shutting down a forum, I am trying to figure out a way to redirect all of the phpbb url"s to a single page.

So for example, I want all urls that that have /viewtopic.php? as part of the url structure

example.com/viewtopic.php?

to redirect to:

example.com/page

It is not as simple as just redirecting all pages on the domain as there are other pages on the site that I don't want redirected.

Anyone with better skills than me have a solution?
6:01 pm on Jan 17, 2013 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



The RegEx pattern of the RewriteRule will need to match the path part of the requested URL, rather than (.*) for all.

The rule target will need to include protocol and hostname and end with the [R=301,L] flags.
6:30 pm on Jan 17, 2013 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks g1smd, long time no see.

I wish I spoke better server geek. :) I am not getting it.

So (.) is replaced by the url structure for the links that are to be redirected and the (*) acts as a wildcard for everything that follows viewtopic.php?

So I tried this, and it obviously didn't have the desired effect.

RewriteEngine On
RewriteRule http://www.example.com/viewtopic.php?* http://www.example.com/page [R=301,L]
8:55 pm on Jan 17, 2013 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Rule pattern matches ONLY the path, in this case viewtopic.php and cannot match hostname or parameters.

(.*) matches any number of characters. Use that when ALL requests need to be processed.
"." matches a single character and "*" means "zero or more times".

In this case you need the exact pattern ^viewtopic\.php with the literal period escaped.
11:11 pm on Jan 17, 2013 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



What is
viewtopic.php?*
intended to mean?

I'd have thought the sequence ?* would get you an immediate error, but possibly not. (Tried it in text editor which speaks regex.) In Regular Expressions * is not a wild card, which I suspect is what you want it to be. And ? is not a literal character. Not that it matters, because you don't mean

...viewtopic.php?* ...

you mean

RewriteCond %{QUERY_STRING} .+
...viewtopic\.php$ ...

or possibly

RewriteCond %{QUERY_STRING} .*
...viewtopic\.php$ ...

which is exactly the same as not having a RewriteCond at all. (Hm. Or is it? Does mod_rewrite distinguish between an absent query and an empty one?)

In theory, "viewtopic.php" always has a parameter-- what mod_rewrite calls a Query String. For your present purposes, does it matter whether the query is legitimate? Does the Forums software itself distinguish between garbage strings and ones that simply point to nonexistent pages (say, page 5 of a 3-page discussion, or topic 43567 when the total number is only 30000)? Quick detour to nearest php/bb forum says that any query string it can't resolve-- or no query at all-- leads to the generic "doesn't exist" message. I hope the googlebot knows this, because otherwise we're in Soft 404 / Duplicate Content / Infinite URL Space territory.
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month