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

XF 1.3 Changed forum location, what do I need to modify in .htaccess?

Discussion in 'XenForo Questions and Support' started by Biker, Aug 5, 2014.

  1. Biker

    Biker Well-Known Member

    I recently changed the installation location for our forum from /forum to /. What I'm trying to do now is redirect anyone who clicks an old link (or old bookmark) from the old URL to the new.

    What would I enter in .htaccess to automatically reroute folks to the proper URL now?

    Here's a copy of what's in place right now:

    Code:
    #   Mod_security can interfere with uploading of content such as attachments. If you
    #   cannot attach files, remove the "#" from the lines below.
    #<IfModule mod_security.c>
    #   SecFilterEngine Off
    #   SecFilterScanPOST Off
    #</IfModule>
    
    ErrorDocument 401 default
    ErrorDocument 403 default
    ErrorDocument 404 default
    ErrorDocument 500 default
    
    <IfModule mod_rewrite.c>
       RewriteEngine On
    
       #   If you are having problems with the rewrite rules, remove the "#" from the
       #   line that begins "RewriteBase" below. You will also have to change the path
       #   of the rewrite to reflect the path to your XenForo installation.
       #RewriteBase /xenforo
    
       #   This line may be needed to enable WebDAV editing with PHP as a CGI.
       #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    
         RewriteCond %{ENV:rwdone} !^yes$
       RewriteCond %{REQUEST_FILENAME} -f [OR]
       RewriteCond %{REQUEST_FILENAME} -l [OR]
       RewriteCond %{REQUEST_FILENAME} -d
       RewriteRule ^.*$ - [NC,L]
       RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
       RewriteRule ^.*$ index.php [NC,L]
       RewriteRule (.*) /%2/$1 [E=rwdone:yes,L]
    </IfModule>
    
     
    Last edited: Aug 5, 2014
  2. Biker

    Biker Well-Known Member

  3. Brogan

    Brogan XenForo Moderator Staff Member

  4. Biker

    Biker Well-Known Member

    Is there any difference or preferred method between the two?
     
  5. Brogan

    Brogan XenForo Moderator Staff Member

  6. Biker

    Biker Well-Known Member

    Hmmm. After doing some digging, seems the folks at Apache prefer a redirect in this case, rather than a rewrite.

    http://httpd.apache.org/docs/trunk/rewrite/avoid.html

    So redirect it is! :)
     
  7. Biker

    Biker Well-Known Member

  8. wickedstangs

    wickedstangs Well-Known Member

    did you resolve this? Can you post up your new .htaccess I had the same issue it looks like.

    Code:
    #    This line may be needed to enable WebDAV editing with PHP as a CGI.
        #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    
        RewriteCond %{REQUEST_FILENAME} -f [OR]
        RewriteCond %{REQUEST_FILENAME} -l [OR]
        RewriteCond %{REQUEST_FILENAME} -d
        RewriteRule ^.*$ - [NC,L]
        RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
        RewriteRule ^.*$ index.php [NC,L]
        RewriteRule ^community/(.*)?$ /$1 [R=301,L]
     
  9. Biker

    Biker Well-Known Member

    @wickedstangs After some digging, hair pulling, and a bit of trial and error, I think I have it licked.

    Code:
    #   Mod_security can interfere with uploading of content such as attachments. If you
    #   cannot attach files, remove the "#" from the lines below.
    #<IfModule mod_security.c>
    #   SecFilterEngine Off
    #   SecFilterScanPOST Off
    #</IfModule>
    
    ErrorDocument 401 default
    ErrorDocument 403 default
    ErrorDocument 404 default
    ErrorDocument 500 default
    
    <IfModule mod_rewrite.c>
       RewriteEngine On
    
       #   If you are having problems with the rewrite rules, remove the "#" from the
       #   line that begins "RewriteBase" below. You will also have to change the path
       #   of the rewrite to reflect the path to your XenForo installation.
       # RewriteBase /
    
       #   This line may be needed to enable WebDAV editing with PHP as a CGI.
       #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    
       RewriteCond %{ENV:rwdone} !^yes$
       RewriteCond %{REQUEST_FILENAME} -f [OR]
       RewriteCond %{REQUEST_FILENAME} -l [OR]
       RewriteCond %{REQUEST_FILENAME} -d
       RedirectMatch 301 ^/forum/?$ http://www.mydomain.org
       RewriteRule ^.*$ - [NC,L]
       RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
       RewriteRule ^.*$ index.php [NC,L]
       RewriteRule (.*) /%2/$1 [E=rwdone:yes,L]
    </IfModule>
    
    Everything appears to work so far. Even mark forums read. Whew!

    Now I just need to figure out why my mod_security rules are bombing httpd on restart. **sigh**
     
    Last edited: Aug 8, 2014
  10. wickedstangs

    wickedstangs Well-Known Member

  11. Biker

    Biker Well-Known Member

    Digging through the error logs, it seems the redirects aren't working as they should, especially with Google.

    I'm noticing it trying to find old threads under /forum and it's getting a 404 Not found. I tested the URL and it's redirecting back to the forum home page, not the thread.
     
  12. wickedstangs

    wickedstangs Well-Known Member

    Just my opinion but, a move is not such a great idea, I did the move and lost all my Google searches..
     
  13. Biker

    Biker Well-Known Member

    I'm really not too concerned about it.

    Some redirects are working, some are not. I have a sneaky hunch it all boils down to what the bot is specifically looking for and how it interacts with the site. Noticing a few mod_security denials as well. I'll just continue to monitor and tweak until I have things where I want 'em.
     

Share This Page