• 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?

Biker

Well-known member
#1
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:

Biker

Well-known member
#6
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

A common use for RewriteRule is to redirect an entire class of URLs. For example, all URLs in the /one directory must be redirected to http://one.example.com/, or perhaps all http requests must be redirected to https.

These situations are better handled by the Redirect directive. Remember that Redirect preserves path information. That is to say, a redirect for a URL /one will also redirect all URLs under that, such as /one/two.html and /one/three/four.html.
So redirect it is! :)
 

wickedstangs

Well-known member
#8
All fixed. :D

RedirectMatch 301 ^/forum/(.*)$ http://www.domain.com/$1 works a treat.
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]
 

Biker

Well-known member
#9
@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:

Biker

Well-known member
#11
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.
 

wickedstangs

Well-known member
#12
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.
Just my opinion but, a move is not such a great idea, I did the move and lost all my Google searches..
 

Biker

Well-known member
#13
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.