homepage Welcome to WebmasterWorld Guest from 54.161.220.160
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
How to redirect forum urls to a single page?
redirecting multiple urls to a single page
pmac

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 4536894 posted 5:58 pm on Jan 17, 2013 (gmt 0)

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?

 

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4536894 posted 6:01 pm on Jan 17, 2013 (gmt 0)

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.

pmac

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 4536894 posted 6:30 pm on Jan 17, 2013 (gmt 0)

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]

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4536894 posted 8:55 pm on Jan 17, 2013 (gmt 0)

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.

lucy24

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



 
Msg#: 4536894 posted 11:11 pm on Jan 17, 2013 (gmt 0)

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved