Forum Moderators: phranque

Message Too Old, No Replies

Using mod_rewrite to move a directory to another

         

Joe Belmaati

7:59 am on Dec 3, 2004 (gmt 0)

10+ Year Member



I am trying to move a discussion forum on my site from /forum/ to / (from directory "forum" to root dir).

I have searched the board and read the Apache tutorial, however I can not localize an existing solution to my question.

In short there's a forum in directory mydomain.com/forum/
This directory will contain url's like mydomain.com/forum/topic1

My hope is to be able to rewrite all requests for files such that the above example would become mydomain.com/topic1

Any help is much appreciated, as well as thoughts on possible problems (SE-related and other).

Sincere thanks,
Joe Belmaati
Copenhagen Denmark

jdMorgan

2:08 pm on Dec 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> My hope is to be able to rewrite all requests for files such that the above example would become mydomain.com/topic1

First, edit the forum script so that it produces URLs (on-page links) in the form: mydomain.com/topic1

Then, create a RewriteRule to rewrite requests for mydomain.com/topic<0-99999> into requests for mydomain.com/forum/topic<0-99999>

In your RewriteRule, you will create and use a back-reference to "copy" the topic number from the requested URL into the actual filepath.

You must take care that there is no file in your root directory named "topic<any_number>", otherwise this will cause problems.

Note that mod_rewrite does not "move" anything; It simply changes the relationship between requested URLs and the corresponding request filepaths in the filesystem. In this case, all it does is to insert "/forum" into the requested URL and pass that new URL as a filename to the Apache content-handler, which serves that file's content (this requested file is your forum script in this case).

Jim

Joe Belmaati

8:28 am on Dec 7, 2004 (gmt 0)

10+ Year Member



Thanks Jim. I've got all my forum rewrite in working condition. I really did not explain my request very well. What I want to do is to move all the content from /forum into my root dir - I've got that all in working condition. But what I want to make sure is that all google hits and people who have bookmarked pages on my site will be served the moved pages....so I guess what I am asking is:

How do I make all requests to
/forum

invisibly rewrite to
/

instead...?

BTW I have found lots of pages describing how to rewrite requests from / to /dir, but none that describe the reverse process. Simply reversing the statements doesn't seem to work...

jdMorgan

1:54 am on Dec 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Joe, you really need to put some study into this... Otherwise, I'm going to have to start billing you by the hour... :)

The references in our charter [webmasterworld.com] are a good place to start.


RewriteRule ^forum/(.*) /$1 [L]

Jim

Joe Belmaati

4:28 am on Dec 8, 2004 (gmt 0)

10+ Year Member



Sincere apologies.