XF 2.2 Redirecting requests to deleted threads

Anatoliy

Well-known member
I deleted a bunch of old (and I thought useless) threads. Now my SEO tool shows that a dozen of them are in Google's SERP, they keep getting visitors from Google, but return 404, which is not good and has to be fixed.

So my question: what is the best way to set 301 redirects for 20-30 urls?
 
Solution
I use .htaccess e.g.


Code:
Redirect 301 /threads/deleted-thread.101 https://yourforum.com/threads/redirect-to-this-one.102

Each redirect on a new line and note the space before https
I use .htaccess e.g.


Code:
Redirect 301 /threads/deleted-thread.101 https://yourforum.com/threads/redirect-to-this-one.102

Each redirect on a new line and note the space before https
 
Solution
Looks like no one posted this fantastic addon from Siropu!

 
I use .htaccess e.g.


Redirect 301 /threads/deleted-thread.101 https://yourforum.com/threads/redirect-to-this-one.102

Each redirect on a new line and note the space before https
That's how I have done it in the past as well.

Can also be used for 410 redirects (thread removed):

Redirect 410 https://yourforum.com/threads/deleted-thread.999/
 
I have a load more than 20 and no issues whatsoever.

It may mean someone clicking a link takes very very slightly longer, but hardly noticeable (try it after clearing your cache).

Very quickly Google will drop the old links anyway and reindex. You should fix any internal links and so the only remaining relevant links are any backlinks for other sites, which is less than likely if the the threads are useless.
 
One more thing, what you are doing is very good for SEO, you are giving Google better quality content.

I sometimes clean up like this. Maybe find several similar threads, merge them all into one. Check for internal links and edit those. I often don't bother with redirects unless I know there are backlinks form other sites.

If there aren't then you can put in a 410 as djbaxter mentioned. Google will then drop the old links and should pick up the new one even without a redirect.
 
Bearing in mind that I have a VPS with super tech support, I don't even need to do it by myself, but just to write a request.
So what exactly should I write to them? That I want them to move those 301 & 410 redirect rules from .htaccess to the server config?
You would add something like this to your Apache Post VirtualHost include...

Code:
<IfModule mod_rewrite.c>
<Directory "/home/XXXyoursitedirectoryhereXXX/public_html">
Options -Indexes
AllowOverride None

RewriteEngine On

# Force SSL
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Force www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [E=HTTPS,R=301,L]

# XenForo
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]
</Directory>

</IfModule>

If you have XenForo in a subdirectory like /community it would look like this:

Code:
<IfModule mod_rewrite.c>
<Directory "/home/XXXyoursitedirectoryhereXXX/public_html">
Options -Indexes
AllowOverride None

RewriteEngine On

# Force SSL
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Force www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [E=HTTPS,R=301,L]
</Directory>

<Directory "/home/XXXyoursitedirectoryhereXXX/public_html/community">
RewriteEngine On

# XenForo
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]
</Directory>

</IfModule>

Make changes as necessary for your specific installation. Your custom rules will go right above the line starting with "# XenForo". Once this is in place and working well, you can delete your .htaccess files from the directory structure they are now completely ignored. Your redirects will now be cached by the server and you have eliminated the performance loss from Apache AllowOverride.
 
Thank you, guys!
My only consern is that after I put 20 lines of redirects in htaccess, each request to the server will be processed slower as the system will have co check 20 times if the requested url matches the one in the list.
Or it will be not noticeable?
 
One more thing: I always like to keep my htaccess down to what is absolutely required. So once Google has picked up a redirect link, and I am confident there are no internal or external backlinks, then I can remove them.

I did uses the free trial of ahrefs.com to check backlinks, but beware they seem to continue spamming you with links after the trial.
 
If possible (that is, you have root access) and are running Apache you should not use .htaccess at all. You should be using the main server configuration to implement your redirects. This goes for the XenForo standard redirects also.

Apache has said this for probably over ten years.

Why not use .htaccess?
  1. The first of these is performance. When AllowOverride is set to allow the use of .htaccess files, httpd will look in every directory for .htaccess files. Thus, permitting .htaccess files causes a performance hit, whether or not you actually even use them! Also, the .htaccess file is loaded every time a document is requested.
  2. Further note that httpd must look for .htaccess files in all higher-level directories, in order to have a full complement of directives that it must apply. Thus for every request it must recompile the .htaccess from the current directory and every parent directory until hitting the site root.
  3. In the case of RewriteRule directives, in .htaccess context these regular expressions must be re-compiled with every request to the directory, whereas if the rules are applied in main server configuration context they are compiled once and cached.
The busier your site, the more performance hit you'll take.

If you have root access, it takes hardly any time at all to move the redirects to the server config. Increase your performance and save your server load for something else, like site growth.
 
If possible (that is, you have root access) and are running Apache you should not use .htaccess at all. You should be using the main server configuration to implement your redirects. This goes for the XenForo standard redirects also.

Apache has said this for probably over ten years.

Why not use .htaccess?
  1. The first of these is performance. When AllowOverride is set to allow the use of .htaccess files, httpd will look in every directory for .htaccess files. Thus, permitting .htaccess files causes a performance hit, whether or not you actually even use them! Also, the .htaccess file is loaded every time a document is requested.
  2. Further note that httpd must look for .htaccess files in all higher-level directories, in order to have a full complement of directives that it must apply. Thus for every request it must recompile the .htaccess from the current directory and every parent directory until hitting the site root.
  3. In the case of RewriteRule directives, in .htaccess context these regular expressions must be re-compiled with every request to the directory, whereas if the rules are applied in main server configuration context they are compiled once and cached.
The busier your site, the more performance hit you'll take.

If you have root access, it takes hardly any time at all to move the redirects to the server config. Increase your performance and save your server load for something else, like site growth.
While all of that is true especially for large websites and forums, adding 20 lines of redirect statements to .htaccess in the root of his forum is not going to make a perceptible impact.

The OP has a simple problem. Don't overcomplicate the solution.

@Anatoliy just go with the .htaccess solution suggested above. You and your forum will be fine.
 
If possible (that is, you have root access) and are running Apache you should not use .htaccess at all. You should be using the main server configuration to implement your redirects.
I do have root access. But I have Nginx. Or Nginx + Apache. I'm not sure.
@Anatoliy just go with the .htaccess solution suggested above. You and your forum will be fine.
Already. )
 
If the original poster can formulate a redirect rule, he has more than enough ability to simply move the .htaccess rules to the server config. We're literally talking ten minutes of work for a XenForo site.
Bearing in mind that I have a VPS with super tech support, I don't even need to do it by myself, but just to write a request.
So what exactly should I write to them? That I want them to move those 301 & 410 redirect rules from .htaccess to the server config?
 
Then I think you're good to go. Just leave them in place for a few months until the old links have a chance to drop out of the Google index and then you can delete them from .htaccess.
 
Top Bottom