htaccess in sub-folder for 301 redirecting affiliate links?

RyanWeb

Affiliate Guard Dog Member
Joined
Apr 9, 2015
Messages
973
Reaction score
412
I haven't seen much on the internet about placing an htaccess file in a subfolder for this purpose.

I have a pretty large htaccess file due to 301 redirects and I don't want that (large) file called everytime someone visits a page on my website. I run wordpress so I will be keeping a smaller htaccess file in the root directory. But my question is, if I make another htaccess file and place it in a /goto/ folder, will THAT htaccess file Only be called when someone clicks on one of my affiliate links /goto/casinoxyz ?

I am asking because I read somewhere that is it more load on the server to have more the one htaccess file. But I can't seem to find much more information on it.

If that doesn't work I guess I could put it in a sub-domain if that world be any different? What would be fastest for site speed?
 

bobby sand

Affiliate Guard Dog Member
Joined
Mar 12, 2015
Messages
42
Reaction score
10
Hey Ryan,

As far as I know you can't add server redirect protocols within a subfolder, the .htaccess file is essentially like a config file which only communicates with the server. The protocol can only be carried out via the root domain, and as such Google or any crawler would only check a htaccess from within the root so would be redundant putting it in a sub folder.

In regards to server bloat, how many page level redirects have you got in your .htaccess. It wouldn't necessarily affect page load speed unless we're talking in the thousands. If I'm doing redirects, I try and consolidate as much as I can, i.e. catch all rules where applicable.

Hope that makes sense and helps :)
 

RyanWeb

Affiliate Guard Dog Member
Joined
Apr 9, 2015
Messages
973
Reaction score
412
As of current I have about 300 lines in my htaccess file, about 20kb .. To be honest I don't know if thats large enough to have any affect on page load times or not.. I feel like it is, but I may be a bit paranoid ;)

I found this "The .htaccess file can be placed on any folder on your site. It has recursive effect. This means that if you place the .htaccess file in your web root (the main folder of your web site) the directives and commands you place in the .htaccess file will have effect on all sub-folders.
If you place a .htaccess file in a sub-folder, its directives will override the ones that you have in your site main folder. That is if you disable directory listing globally for your site by placing the proper line in the .htaccess file in your main folder, you can then enable directory listing only for a particular sub-folder with another .htaccess file and the proper directive." - besthostratings.com/articles/htaccess.html

But that sounds like its getting completed. Maybe I'll just throw it in a subdomain and call it a day as I haven't changed over all my actual links on my pages yet.. I don't want to go through redo everything later.
 

AussieDave

24 years & still going!
Joined
Nov 28, 2013
Messages
4,993
Reaction score
3,532
Bobby Sand is on the money :)

htaccess redirects must reside on the site's root. There are certain directives which can sit in a htaccess in a folder but a redirect isn't one of them.

htaccess file(s) are not only processed insanely fast but with very little overhead. You need to have literally 1000's of redirects etc etc to even notice a difference.
 

AussieDave

24 years & still going!
Joined
Nov 28, 2013
Messages
4,993
Reaction score
3,532
Question... Do you want to redirect just the folder (being casino) or... all the pages contained within & or concursive folders/files there after.

EG -yourdomain.com/casinos/games/this-is-a-funky-slot (trailing slash or no trailing slash)?
 

RyanWeb

Affiliate Guard Dog Member
Joined
Apr 9, 2015
Messages
973
Reaction score
412
Good to know there is very little overhead then!

I only want to 301 redirect my affiliate links through a single folder. Example:

Redirect 301 /goto/clubworldcasino clubworldaffiliatelink
Redirect 301 /goto/clubeurocasino clubeuroaffiliatelink
Redirect 301 /goto/aladdinsgoldcasino aladdinsaffiliatelink

and so on.
 

AussieDave

24 years & still going!
Joined
Nov 28, 2013
Messages
4,993
Reaction score
3,532
Can I ask why you want to do this? Is it to cloak your aff links?
 

RyanWeb

Affiliate Guard Dog Member
Joined
Apr 9, 2015
Messages
973
Reaction score
412
Yes, but mostly for easy update as I have around a thousand pages and growing.. I am trying to consolidate things for time management. So next time I need to update a link, I can update via the htaccess file and not search for every link on my site.
 

RyanWeb

Affiliate Guard Dog Member
Joined
Apr 9, 2015
Messages
973
Reaction score
412
I was going to get a different domain all together, and run all my sites through that for url redirects.. But then I am thinking, if that server went down for a bit, all my links would be dead in the water. Might be smarter to do them each sitewide but local.. As I have a few different hosts.
 

AussieDave

24 years & still going!
Joined
Nov 28, 2013
Messages
4,993
Reaction score
3,532
That's a fair call, I do the same thing but a little differently. Instead of using a htacess file, I use a php file for each program. If the link changes, all I do is update one file ;)

EG - mydomain.com/goto/32red.php

This page contains the following code.
Code:
<?php
$url = /*starturl*/"http://your-casino-affiliate-link-goes-here"/*endurl*/;
header("Location: ".$url);
?>

It's uploaded to the goto folder and bob's your uncle ;)

So a link or a banner pointing to a casino would be:
Code:
<a rel="nofollow" href="http://www.yourdomain.com/goto/the-casino-name.php" target="_blank">insert text link or banner image</a>

If you don't want google to crawl/follow/index that folder, you can add:

User-agent: *
Disallow: /goto/

in robots.txt file.
 

AussieDave

24 years & still going!
Joined
Nov 28, 2013
Messages
4,993
Reaction score
3,532
I don't bother doing that because Google prefers not to be kept out.
However in instances such as WP with wp-admin and wp-includes, I always Disallow (block) these is robots.txt.

The following has nothing to do with the redirects. Just thought I'd add it ;)

If you've got a static IP through your ISP you can go one better (tight security for WP admin folder) and add:

a htaccess file to the wp-admin folder, in thaty file you'd add:

Code:
order deny,allow
deny from all
allow from 127.0.0.1 (replace with your static IP)

Set that file permssion to 644
 
Last edited:

AussieDave

24 years & still going!
Joined
Nov 28, 2013
Messages
4,993
Reaction score
3,532
The beauty of using the php redirect as apposed to htaccess... Different boxes, especially shared hosting where you don't have access to anything, you can run into problems with htaccess. Where as using a php redirect, your not having to worry about getting it to work.

It's a PITA (pain in the ass), when you get a 500 internal error from a redirect which works on one host but not another. So you then have to screw around getting it to work :(
 

RyanWeb

Affiliate Guard Dog Member
Joined
Apr 9, 2015
Messages
973
Reaction score
412
Thank you for your help I really appreciate it! Im going to read a little more about the htaccess vs php redirect. I always nofollow all my aff links...

Yes I pretty much always nofollow my aff links so I will most likely Disallow: /goto/

Thank you again, you have been helpful.. Now I have options!
 

RyanWeb

Affiliate Guard Dog Member
Joined
Apr 9, 2015
Messages
973
Reaction score
412
The beauty of using the php redirect as apposed to htaccess... Different boxes, especially shared hosting where you don't have access to anything, you can run into problems with htaccess. Where as using a php redirect, your not having to worry about getting it to work.

It's a PITA (pain in the ass), when you get a 500 internal error from a redirect which works on one host but not another. So you then have to screw around getting it to work :(
That is true as well... As I have a few different servers.. I can just create the folder with the .php files locally then drop and drag them in for each host and go.
 

AussieDave

24 years & still going!
Joined
Nov 28, 2013
Messages
4,993
Reaction score
3,532
It's server compiled, anyone stopping the process and pulling the source code, can't see anything cause it's all php ;)
 

AussieDave

24 years & still going!
Joined
Nov 28, 2013
Messages
4,993
Reaction score
3,532
You could actually mod that script further and include a basic click count and write each hit to a txt file. I ran something similar ages ago. I tend to like to know how many hits a link is actually getting my side and not be reliant on aff program stats. That way if figures fluctate too much, you can question it with your AM ;)

BTW your very welcome Ryan, thanks for the kudos!
 
Top