Question About Redirection

yavuz

Well-known member
Hi, I did a quick search if there was previously posted thread about URL redirection avaliable (searched for "redirection") but there wasn't answering to my question.

So basicly, I have a forum installed in the root folder and a Wordpress blog installed on /blog. I would like to put my forum inside a /forum folder and my wordpress blog in root. How do I do that without loosing my links?

I'm running apache webserver with a nginx module.
 
Normally you could use a 301 redirect in a .htaccess file at the original location:

Code:
Redirect 301 / /forum/

But that won't work since you are moving Wordpress to the old location.

You could use RedirectMatch with a regex to redirect only XenForo's URL routes:

Code:
RedirectMatch 301 ^/(threads|forums)/(.*)$ /forum/$1/$2

"threads" and "forums" are the most important routes. You can add others if you want.

This syntax assumes you are using friendly URLs in XenForo.
 
You could use RedirectMatch with a regex to redirect only XenForo's URL routes:

Code:
RedirectMatch 301 ^/(threads|forums)/(.*)$ /forum/$1/$2

"threads" and "forums" are the most important routes. You can add others if you want.

This syntax assumes you are using friendly URLs in XenForo.

Thanks Jake for the response. So I put it into my .htaccess and all threads and forums will be redirected to their new location? To put other pages or individual add-on pages like XenMedio (/media) or members (/members) is this correct:

Code:
RedirectMatch 301 ^/(threads|forums|media|members)/(.*)$ /forum/$1/$2
 
I'm in a similar situation but trying to accomplish the opposite. I've had my wordpress blog installed in my root for years and only recently installed XenForo in the /forum directory. The forum has now outgrown the blog and I want the XenForo forum index to appear when people go to the root domain, www.backcountrypost.com.

I've changed the settings and permalinks in Wordpress so that everything is working properly in /blog but left the wordpress files in the root.

So now I just need to do something so that my XenForo install appears at the root. It would be ideal if I didn't have to do this as a 301 redirect to /forum, especially since when I tried that, it screwed up all of my blog redirects to /blog. If possible I would like to leave my XenForo files in the /forum folder and just add an index.php or whatever is necessary to the root to make this happen.

Thoughts?
 
I'm in a similar situation but trying to accomplish the opposite. I've had my wordpress blog installed in my root for years and only recently installed XenForo in the /forum directory. The forum has now outgrown the blog and I want the XenForo forum index to appear when people go to the root domain, www.backcountrypost.com.

I've changed the settings and permalinks in Wordpress so that everything is working properly in /blog but left the wordpress files in the root.

So now I just need to do something so that my XenForo install appears at the root. It would be ideal if I didn't have to do this as a 301 redirect to /forum, especially since when I tried that, it screwed up all of my blog redirects to /blog. If possible I would like to leave my XenForo files in the /forum folder and just add an index.php or whatever is necessary to the root to make this happen.

Thoughts?

You could add an index.php with a redirect:

Code:
<?php

header("Location: http://www.apple.com/");

?>
 
You could add an index.php with a redirect:


I tried that as well. For some reason even that solution breaks the redirects from my old WP links to my new WP links. At this point I'd be ecstatic to find any solution that forwards backcountrypost.com to backcountrypost.com/forum without breaking those WP redirects. Here is the code I'm dealing with, maybe someone has an idea?

My old blog links looked like this:

http://backcountrypost.com/?p=1702

And my new links look like this:

http://backcountrypost.com/blog/vermilion-cliffs/coyote-buttes-north-january-2012/

That all goes off without a hitch until I do anything to forward backcountrypost.com to backcountrypost.com/forum. I've tried adding code to htaccess and I have also tried putting a index.php redirect in the root. Either way breaks the old links from forwarding to the new links. The new links still work, it just won't forward the old links to the new links which is pretty important as that is still a major source of traffic.

The code in my .htaccess file looks ilke this:

Code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

If there is no solution to get my root to forward to /forum, what if I moved XenForo into the root? I imagine it would be extremely difficult if not impossible to make the htaccess file above jive with XF's htaccess?
 
My old blog links looked like this:

http://backcountrypost.com/?p=1702

That is using index.php which is why you can't replace it without breaking WP.

For your situation I recommend the same redirects I posted before:

Code:
RedirectMatch 301 ^/(threads|forums)/(.*)$ /forum/$1/$2

But use them to specify prefixes for WP instead of XF. Using your example:

Rich (BB code):
RedirectMatch 301 ^/(vermilion-cliffs|any|other|prefixes)/(.*)$ /forum/$1/$2
 
But use them to specify prefixes for WP instead of XF. Using your example:

Rich (BB code):
RedirectMatch 301 ^/(vermilion-cliffs|any|other|prefixes)/(.*)$ /forum/$1/$2

Thank you, Jake! So do I need to edit the existing WP code in my htaccess or just add that to it? And I have about 15-20 categories that would need to go in with 'vermilion cliffs'. Do I just plug them all in on a single line like your example shows?
 
It would go in your web root in order to redirect WP requests from the root to /blog.

And it would replace the existing code in my root htaccess file which is currently handling the WP requests, correct?

current code:
Code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
 
I tried out the code you recommended and it doesn't appear to work. It seems to forward to the correct URL's but somehow those URL's no longer work.

Here is the code I used with all of my categories added:

Code:
RedirectMatch 301 ^/(vermilion-cliffs|alaska|archesnp|arizona-strip|bear-river-range|california|canyonlandsnp|cedar-mesa|escalante-area|great-salt-lake|uintas|idaho|mexico|misc|moab-area|oregon|robbers-roost|san-rafael-swell|uncategorized|wasatch|wind-rivers|greater-yellowstone-area|zion)/(.*)$ /forum/$1/$2

When I did that, my root still loaded to my root (not to /forum), and all of my blog links were broken, even when I was trying to access the full, current URLs.

For example, I got a 404 Not Found error when trying to visit http://backcountrypost.com/blog/zion/mystery-canyon-zion-october-2011/ which is the correct URL. Switching back to the old WP code in the ht access restored functionality.

Any ideas?
 
Isn't WP installed in /blog? In that case you need to redirect to that directory, but you have /forum/$1/$2 at the end. It should be /blog/$1/$2

This redirect would replace the WP htaccess in the root. The WP htaccess should now exist inside of the /blog directory.

I can take a look if you give me FTP access.
 
Isn't WP installed in /blog? In that case you need to redirect to that directory, but you have /forum/$1/$2 at the end. It should be /blog/$1/$2

This redirect would replace the WP htaccess in the root. The WP htaccess should now exist inside of the /blog directory.

I can take a look if you give me FTP access.

I actually have WP installed in the root. I just changed it so that it loads out of /blog and shows all the URLs as /blog. The only thing I have in that directory is an index.php file for the WP install.

I'll PM you about the FTP.

Thanks!
 
Back
Top Bottom