Redircting with .htaccess in Apache

This is an archive of the phpBB 2.0.x support forum. Support for phpBB2 has now ended.
Forum rules
Following phpBB2's EoL, this forum is now archived for reference purposes only.
Please see the following announcement for more information: viewtopic.php?f=14&t=1385785
Locked
kprobbins
Registered User
Posts: 10
Joined: Tue Mar 08, 2005 8:31 am
Contact:

Redircting with .htaccess in Apache

Post by kprobbins »

So, in a pre-emptive attempt to not have to install phpBB 3.0 in a director called /phpBB2/, I've moved the boards on a site I'm working on to a folder called /forums/.

So, instead of going here:
http://www.yesand.com/phpBB2/

Users will go here:
http://www.yesand.com/forums/

I put a file redirect in the old phpBB2 directory, but that's simple stuff.

What I am REALLY interested in knowing is how to redirect traffic from URLs to other posts that users have referenced within the forums themselves to go the right spot and make the right call to the server. Such that...

A call for the URL:
http://www.yesand.com/phpBB2/viewtopic.php?t=18476

Will perform an external REDIRECT to the following, new location:
http://www.yesand.com/forums/viewtopic.php?t=18476

I'd like to do this seamlessly.

I'm not a back-end person, so I don't know much about Apache servers, .htaccess files and mod_rewrite other than what I can find in the documentation at the Apache site. I'm sure it's all there, but I can't figure out regular expressions, nor do I understand Perl to be able to make some sort of call to a mapping file that I would have to create, if that is the case.

Could someone please help me out with this? (read: tell me exactly how to do it because I don't can't figure it out)

Also, I think this is something worth considering including in the release of phpBB 3.0 since its default directory might likely be set to /phpBB3/ rather than /phpBB2/. This is why I'd rather use a generic word such as "forums". The admin folks here might consider simplifying this to just /phpBB/ and dropping the version number in folder default... you know, kinda like this one is right here on this server.

Thanks in advance for letting me tap your wonderful minds.

Cheers,
Kevin.

User avatar
SnowManrcd
Registered User
Posts: 155
Joined: Tue Oct 21, 2003 6:05 pm

Post by SnowManrcd »

I've done this let me dig it up for you (lol but knowing this place someone will beet me to it)
-SnowMan

User avatar
SnowManrcd
Registered User
Posts: 155
Joined: Tue Oct 21, 2003 6:05 pm

Post by SnowManrcd »

For files

Code: Select all

Redirect /olddirectory/oldfile.html http://yoursite.com/newdirectory/newfile.html
For Directorys

Code: Select all

Redirect /olddirectory http://yoursite.com/newdirectory/
just place it in a .htaccess file and place it in your old dir
-SnowMan

kprobbins
Registered User
Posts: 10
Joined: Tue Mar 08, 2005 8:31 am
Contact:

Post by kprobbins »

Sure, that works for static pages and I know how to do that. What I'm saying is that I need to be able to weed out all calls to the server for looking for:

http://www.yesand.com/phpBB2/*

and replace it with:

http://www.yesand.com/forums/*

where * is the wildcard for "anything and everything."

So, if a URL reads:
http://www.server.com/olddirectory/data ... .link.part

it can easily forward them to:
http://www.server.com/newdirectory/data ... .link.part


It's kind of hard to explain it in print because it looks like static references, but I want to map everything in the "olddirector" to everything in the "newdirectory" and it is impossible to redirect every single instance.

for example, if you look at this post:
http://69.13.84.146/forums/viewtopic.ph ... 571#291571

it has references to other posts and threads in that very same phpBB site. with the forums now in a /forums/ directory and not the old /phpBB2/ directory, those links do not work.

I can't change them, but I figure I can setup something in the .htaccess file that will tell the browser that those links no longer exist at Dynamic Location A, you can now find them at Dynamic Location B.

I hope that helps explain it further

Thanks for your help do far, though.

kprobbins
Registered User
Posts: 10
Joined: Tue Mar 08, 2005 8:31 am
Contact:

Post by kprobbins »

and i apologize for all the typos. it's 4 a.m.

Mr. Sharkey
Registered User
Posts: 635
Joined: Sun Mar 28, 2004 5:42 pm

Post by Mr. Sharkey »

I just dealt with a similar problem. What you will need is an .htaccess that redirects all www.yesand.com/phpBB2/ requests to a PHP script that appends the variable info viewtopic.php?p=291571 (or whatever the request is), into a template containing the www.yesand.com/forum/ address, resulting in a brief redirection page and a refresh to the new page.

.htaccess is not capable of this on it's own, AFAIK.

kprobbins
Registered User
Posts: 10
Joined: Tue Mar 08, 2005 8:31 am
Contact:

Post by kprobbins »

Could you display such interesting files for a little retarded chap like myself? Surely you could spare a tuppence.

Mr. Sharkey
Registered User
Posts: 635
Joined: Sun Mar 28, 2004 5:42 pm

Post by Mr. Sharkey »

How did I know you were going to ask?

Give me about 8 hours, I can't justify pounding the keyboard on such a nice day. I'll need to adjust the php script I'm using a bit, then I'll test it and post the code.

Maybe I should apply for a MOD verification when I'm done?

User avatar
SnowManrcd
Registered User
Posts: 155
Joined: Tue Oct 21, 2003 6:05 pm

Post by SnowManrcd »

kprobbins wrote: Sure, that works for static pages and I know how to do that. What I'm saying is that I need to be able to weed out all calls to the server for looking for:

http://www.yesand.com/phpBB2/*

and replace it with:

http://www.yesand.com/forums/*


yes I understand taht you need to redirect the entire directory. dont give it a file name just the directorys then it will pass the URL to the new Directroy I did the exact same thing you are trying to do when I changed domains.
Mr. Sharkey wrote: .htaccess is not capable of this on it's own, AFAIK.
Yes it is use the following
SnowManrcd wrote: For Directorys

Code: Select all

Redirect /olddirectory http://yoursite.com/newdirectory/
just place it in a .htaccess file and place it in your old dir
-SnowMan

Mr. Sharkey
Registered User
Posts: 635
Joined: Sun Mar 28, 2004 5:42 pm

Post by Mr. Sharkey »

Hey, whatdayaknow, it works! I wouldn't have thought that .htaccess would pass the variables along, but it finds the new directory and topic just fine.

Thanks, now I don't have to labor over the keyboard tonight.

The issue I wrote the php script for was a bit different, so no time wasted there...

User avatar
SnowManrcd
Registered User
Posts: 155
Joined: Tue Oct 21, 2003 6:05 pm

Post by SnowManrcd »

glad I could help I did the same thing when I changed my domain name, I was operating under a friends domain and I got my own finally. so I needed a way to redirect everything over.
-SnowMan

murnauvsbuñuel
Registered User
Posts: 177
Joined: Mon Jun 20, 2005 9:49 am

Re: Redircting with .htaccess in Apache

Post by murnauvsbuñuel »

i had the same question that kprobbins

before i had install php in a folder named "phpBB2" http://www.mydomain.com/phpBB2/ but now i have update my forum in other folder named "foros" http://www.mydomain.com/foros/

that work fine, thanks SnowManrcd. Is the best way?
SnowManrcd wrote: For files

Code: Select all

Redirect /olddirectory/oldfile.html http://yoursite.com/newdirectory/newfile.html
For Directorys

Code: Select all

Redirect /olddirectory http://yoursite.com/newdirectory/
just place it in a .htaccess file and place it in your old dir


For example before the URLs board of phpbb.com were /phpbb/* now are /community/* is that the way done by phpBB Team??

thanks
sorry for my bad english i am spanish.
ImagemxBB Portal the best portal to phpBB2

Locked

Return to “2.0.x Support Forum”