How to 301 redirect forum to subdomain

Discussions about Apache mod Rewrite, .htaccess, Use, experiences ... URL Rewriting.

Moderator: Moderators

How to 301 redirect forum to subdomain

Postby visio » Wed Jun 06, 2007 6:10 pm

I got everything working. Now I want to redirect my forums from domain.com/forums to forums.domain.com

I tried the following:

Code: Select all
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$
RewriteRule ^forums/(.*) http://forums.domain.com/$1 [R=301,L]


But it didn't work. How do I do this with both advanced mod rewrite installed and zero dup?
visio
 
Posts: 22
Joined: Thu May 31, 2007 6:27 pm

Advertisement

Postby dcz » Wed Jun 06, 2007 8:49 pm

First, you will need to update phpBB config, to make sure it's using the sub domain as a domain, eg "forums.domain.com", and make sure the script path is set to / and not forum/ like before.

For the cookie setting, it looks like you already did the right thing, the dot allows all sub domains at once, so don't touch it.

Then, about the .hatccess it's the same, you're going from a sub folder install to a root install.
So get rid of the current forum .htaccess in the root level and put it, after you've removed all occurrences of "forum/" in it (we don't need to mention a path anymore, the forum is installed in the sub forum's root).

Then, in the main domain's root .htaccess, add this :

Code: Select all
RewriteRule ^forums/(.*) http://forums.example.com/$1 [QSA,R=301]


To http 301 redirect all calls to the forum/ folder (thus from the main domain) to the sud domain.

Add this rewriterule after the www prefix redirection for example, or as you very first rewriterule after mod_rewrite was started.

And it will be it, as long as, of course, the sub domain itself does already works.

++
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21398
Joined: Fri Apr 28, 2006 9:03 pm

Postby visio » Wed Jun 06, 2007 10:19 pm

It didn't work. when I do what you say it looks right but when I click a board it gives 404.
visio
 
Posts: 22
Joined: Thu May 31, 2007 6:27 pm

Postby dcz » Fri Jun 08, 2007 9:06 pm

Can you tell me precisely where you put the forum .htaccess and post it's content here ?

As well, tell me if there is another .htaccess in the main domain's root.

The sub domain obviously needs to be set up properly as well.

Then, a link could help out to help you out ;)

++
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21398
Joined: Fri Apr 28, 2006 9:03 pm

Postby visio » Mon Jun 11, 2007 12:37 pm

Well I took it off because it wasn't working and while it was on it screwed up the folder option too.

I would be happy to give a link. Please tell me how I can do this for just the home page, I tried a normal ahref link but it didn't show up.
visio
 
Posts: 22
Joined: Thu May 31, 2007 6:27 pm

Postby dcz » Mon Jun 11, 2007 1:52 pm

You can try with an extra L, for last, in the rewriterule :

Code: Select all
RewriteRule ^forums/(.*) http://forums.example.com/$1 [QSA,R=301,L]


To post a link, just past the full url in the post, hit preview and you'll see it clickable, you can as well use the url bbcode, but it's not required.

++
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21398
Joined: Fri Apr 28, 2006 9:03 pm

Postby visio » Wed Aug 08, 2007 1:11 am

I have got the forums to work properly on the subdomain so forums.1stsearchenginerankings.com works fine however 1stsearchenginerankings.com/forums is not redirecting to forums.1stsearchenginerankings.com


Here is what is in my .htaccesss


MAIN .htaccess:

Code: Select all
#Options +FollowSymlinks
RewriteEngine On
RewriteBase /

RedirectMatch permanent ^/forums http://forums.1stsearchenginerankings.com/$1

RewriteCond %{HTTP_HOST} ^1stsearchenginerankings.com [NC]
RewriteRule ^(.*)$ http://www.1stsearchenginerankings.com/$1 [L,R=301]


# -FrontPage-

IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName www.1stsearchenginerankings.com
AuthUserFile /home/search/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/search/public_html/_vti_pvt/service.grp


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress


AddHandler application/x-httpd-php5 .php






FORUMS .htaccess


Code: Select all
#Options +FollowSymlinks
RewriteEngine On
RewriteBase /

#########################################################
# PHPBB SEO REWRITE RULES #
#########################################################
# AUTHOR : DCZ http://www.phpbb-seo.com/
# STARTED : 01/2006
#####################################################
# FORUMS PAGES
########################
# FORUM INDEX (un-comment if used)
RewriteRule ^index\.html$ /index.php [QSA,L,NC]
# FORUM PROTECTION RULE
RewriteRule ^[a-z0-9_-]*/([^/]+\.html)$ /index.php [R=301,L,NC]
# CATEGORIES
RewriteRule ^[a-z0-9_-]*-c([0-9]+)\.html$ /index.php?c=$1 [QSA,L,NC]
# PAGINATED FORUM
RewriteRule ^[a-z0-9_-]*-f([0-9]+)-([0-9]+)\.html$ /viewforum.php?f=$1&start=$2 [QSA,L,NC]
# FORUM
RewriteRule ^[a-z0-9_-]*-f([0-9]+)\.html$ /viewforum.php?f=$1 [QSA,L,NC]
# PAGINATED TOPIC
RewriteRule ^[a-z0-9_-]*-t([0-9]+)-([0-9]+)\.html$ /viewtopic.php?t=$1&start=$2 [QSA,L,NC]
# TOPIC
RewriteRule ^[a-z0-9_-]*-t([0-9]+)\.html$ /viewtopic.php?t=$1 [QSA,L,NC]
# POST
RewriteRule ^post([0-9]+)\.html$ /viewtopic.php?p=$1 [QSA,L,NC]
#PROFILES
RewriteRule ^member([0-9]+)\.html$ /profile.php?mode=viewprofile&u=$1 [QSA,L,NC]
# END PHPBB PAGES
#####################################################



I am so fed up with this that if anybody can fix it I am willing to pay for it.
visio
 
Posts: 22
Joined: Thu May 31, 2007 6:27 pm

Postby SeO » Wed Aug 08, 2007 8:58 am

Try adding :

Code: Select all
RewriteRule ^forum/(.*)$ http://forum.1stsearchenginerankings.com/$1 [QSA,L,R=301]


After :

Code: Select all
RewriteRule ^(.*)$ http://www.1stsearchenginerankings.com/$1 [L,R=301]


In your main domain .htaccess.
SeO
Admin
Admin
 
Posts: 6334
Joined: Wed Mar 15, 2006 9:41 pm

Postby visio » Wed Aug 08, 2007 11:27 am

SeO wrote:Try adding :

Code: Select all
RewriteRule ^forum/(.*)$ http://forum.1stsearchenginerankings.com/$1 [QSA,L,R=301]


After :

Code: Select all
RewriteRule ^(.*)$ http://www.1stsearchenginerankings.com/$1 [L,R=301]


In your main domain .htaccess.


Thanks for your reply!

I added that(added an 's' too as it is forums not forum :P) - 1stsearchenginerankings.com/forums redirects properly now(I guess, the browser accepts it) - However a request for this url:
http://www.1stsearchenginerankings.com/ ... on-f1.html

does not redirect to http://forums.1stsearchenginerankings.c ... on-f1.html
(although if typed in it will work) - instead the first url redirects to this:

http://forums.1stsearchenginerankings.com/?f=1

Now that is the way the urls were before the mod-rewrite. Keep in mind the url bar said it redirected to http://forums.1stsearchenginerankings.com/?f=1 but it still displayed the forum home page.

If you can make sense of all that more power to you...
visio
 
Posts: 22
Joined: Thu May 31, 2007 6:27 pm

Postby SeO » Wed Aug 08, 2007 12:43 pm

mmm

Try :
Code: Select all
RewriteRule ^forums/(.*)$ http://forums.1stsearchenginerankings.com/$1 [L,R=301]
SeO
Admin
Admin
 
Posts: 6334
Joined: Wed Mar 15, 2006 9:41 pm

Postby visio » Wed Aug 08, 2007 1:05 pm

SeO wrote:mmm

Try :
Code: Select all
RewriteRule ^forums/(.*)$ http://forums.1stsearchenginerankings.com/$1 [L,R=301]


Hmm nope returns the same results as the other you posted.
visio
 
Posts: 22
Joined: Thu May 31, 2007 6:27 pm

Postby visio » Wed Aug 08, 2007 1:07 pm

BTW I left

Code: Select all
RedirectMatch permanent ^/forums http://forums.1stsearchenginerankings.com/$1
in the .htaccess- was I supposed to remove that? I tried it in both instances provided and removing the above and inserting only the code you gave gives a 404 error when requesting: http://www.1stsearchenginerankings.com/ ... on-f1.html
visio
 
Posts: 22
Joined: Thu May 31, 2007 6:27 pm

Postby SeO » Wed Aug 08, 2007 1:53 pm

You should only use one method to do the same thing, with redirectmatch, you still need to capture the part you want to use, should then be :

Code: Select all
RedirectMatch permanent ^/forums/(.*)$ http://forums.1stsearchenginerankings.com/$1

or:
Code: Select all
RedirectMatch permanent ^forums/(.*)$ http://forums.1stsearchenginerankings.com/$1
SeO
Admin
Admin
 
Posts: 6334
Joined: Wed Mar 15, 2006 9:41 pm

Postby visio » Wed Aug 08, 2007 2:13 pm

Okay I used the first example and it gave 404 as usual... I tried the second and it worked... sort of.

A request for: http://forums.1stsearchenginerankings.c ... on-f1.html did bring up the appropriate page however somehow this got added to the end of the url: ?f=1 so it returns:
http://forums.1stsearchenginerankings.c ... 1.html?f=1

Why is it doing that?
visio
 
Posts: 22
Joined: Thu May 31, 2007 6:27 pm

Postby visio » Thu Aug 09, 2007 11:26 am

Sorry I messed up on the last post :P

This is what I meant:

Okay I used the first example and it gave 404 as usual... I tried the second and it worked... sort of.

A request for: http://1stsearchenginerankings.com/forums/general-discussion-f1.html did bring up the appropriate page however somehow this got added to the end of the url: ?f=1 so it returns:
http://forums.1stsearchenginerankings.c ... 1.html?f=1

Why is it doing that? - Thanks for any suggestions!
visio
 
Posts: 22
Joined: Thu May 31, 2007 6:27 pm

Next

Return to Apache mod Rewrite

 


  • Related topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 2 guests