1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Question About Redirection

Discussion in 'XenForo Questions and Support' started by yavuz, Sep 30, 2011.

  1. yavuz

    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.
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    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.
     
  3. yavuz

    yavuz Well-Known Member

    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
    
     
  4. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Yes. Exactly correct.

    I just hope Wordpress doesn't share any of those same routes.
     
  5. yavuz

    yavuz Well-Known Member

    is there a wat to determine if? all my wp blog links have /blog in them..
     
  6. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    "blog" is currently the directory name so that will go away. As long as your current Wordpress links don't contain any of these strings you will be fine:

    /threads/
    /forums/
    /media/
    /members/
     
    yavuz likes this.
  7. yavuz

    yavuz Well-Known Member

    Nope they do not. Ill give it a try tonight Jake. thanks again.
     
  8. ibenick

    ibenick Active Member

    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?
     
  9. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    You could add an index.php with a redirect:

    Code:
    <?php
    
    header("Location: http://www.apple.com/");
    
    ?>
    
     
  10. ibenick

    ibenick Active Member


    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?
     
  11. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    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:

    Code:
    RedirectMatch 301 ^/(vermilion-cliffs|any|other|prefixes)/(.*)$ /forum/$1/$2
    
     
  12. ibenick

    ibenick Active Member

    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?
     
  13. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    It would go in your web root in order to redirect WP requests from the root to /blog.
     
  14. ibenick

    ibenick Active Member

    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>
     
  15. ibenick

    ibenick Active Member

    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?
     
  16. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    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.
     
  17. ibenick

    ibenick Active Member

    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!
     

Share This Page