.htaccess tutorial

htaccess Elite


Redirect old versions

Ask your mod_rewrite and Redirection questions here, and get answers!

Redirect old versions

New postby Echilon » 07 Mar 2009 11:28

Currently, every time I release a new version of my software I add a line to htaccess that redirects all requets for old versions to the homepage of my site, but I'm starting to end up with too many htaccess rules to be maintainable. Is there a way I can redirect all requets for version numbers less than a certain number?

Eg:If the current version is 1.40, I have this:
Code: Select all
Redirect 301 /releases/myproduct_1.0.zip http://www.myproduct.com/
Redirect 301 /releases/myproduct_1.10.zip http://www.myproduct.com/
Redirect 301 /releases/myproduct_1.20.zip http://www.myproduct.com/
Redirect 301 /releases/myproduct_1.30.zip http://www.myproduct.com/

Could I use something like:
Code: Select all
Redirect 301 /releases/myproduct_(\d<1.40).zip http://www.myproduct.com/
Echilon
 
Posts: 3
Joined: 07 Mar 2009 11:24

Re: Redirect old versions

New postby spaz » 08 Mar 2009 06:13

* Unless I am misunderstanding your question this will help, it will cover all releases that have been made and
all future releases.

* All requests made to the "releases folder" no matter the version would be directed to your home page

Redirect 302 /releases/ http://www.myproduct.com/
spaz
 
Posts: 4
Joined: 04 Feb 2009 20:41

Re: Redirect old versions

New postby Echilon » 08 Mar 2009 08:26

But that would also redirect the current version.
Echilon
 
Posts: 3
Joined: 07 Mar 2009 11:24

Re: Redirect old versions

New postby spaz » 08 Mar 2009 08:46

Yes it would and I thought about that after I had already posted. The below is more detailed.
* Any saved Favorite, Bookmark or any link out in cyber-land,
with www or non www,
(example):
* www
http://www.myproduct.com/releases/myproduct_1.0.zip
http://www.myproduct.com/releases/myproduct_1.10.zip
* non www
http://myproduct.com/releases/myproduct_1.0.zip
http://myproduct.com/releases/myproduct_1.10.zip

will be forced to start from your home page.
Even your newest release link "if not clicked on from" your home page will not work.
# This also works great for curbing Hot-Linking, just change to:

(examples)
RewriteCond %{REQUEST_URI} ^/image-folder.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?myproduct.com/.*$ [NC]
RewriteRule .* - [F,L]

RewriteCond %{REQUEST_URI} ^/any-file-folder.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?myproduct.com/.*$ [NC]
RewriteRule .* - [F,L]

#####################################################################
#
This should meet your need.
This all is assuming, that Mod Rewrite is enabled on your server, (most do).
The below will force any requests to "anything" in the releases folder be made from your home page link.
#
* Change domain name where needed.
#####################################################################

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
#
# MaxRedirects
RewriteOptions MaxRedirects=3
#
# Loop Stopper
RewriteCond %{ENV:REDIRECT_STATUS} ^.
RewriteRule ^ - [L]
#
# Releases
RewriteCond %{REQUEST_URI} ^/releases.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?myproduct.com/.*$ [NC]
RewriteRule ^(.*)$ http://www.myproduct.com/ [R=301,L]
#
</IfModule>
#
# The below can be deleted if you have it already
# Htaccess - Htpasswd Protection
<FilesMatch "^.*\.([Hh][Tt][Aa]|[Hh][Tt][Pp])">
order allow,deny
deny from all
satisfy all
</FilesMatch>
#
Options All -Indexes
IndexIgnore */*

))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

* Failed to mention that if not allowed to crawl the releases folder:: bots, scrapers will be directed to home page as well.
* I am providing details that may not be necessary for those who have more understanding,
* But for those that are learning, like myself, I hope that it will help them grasp this stuff a little easier.

# Releases

RewriteCond %{REQUEST_URI} ^/releases.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?myproduct.com/.*$ [NC]

* Example for allowance if name is any-where within the User Agent field * Remember user agent can be spoofed

RewriteCond %{HTTP_USER_AGENT !GoogleBot|Slurp|Teoma|bad-bot|content-scraper [NC]


RewriteRule ^(.*)$ http://www.myproduct.com/ [R=301,L]

Hope everything is beneficial, Spaz
Last edited by spaz on 08 Mar 2009 16:43, edited 1 time in total.
spaz
 
Posts: 4
Joined: 04 Feb 2009 20:41

Re: Redirect old versions

New postby Echilon » 08 Mar 2009 10:47

Thanks, that was way more than I was expecting and it looks like it should work. Cheers :)
Echilon
 
Posts: 3
Joined: 07 Mar 2009 11:24


Return to Redirect or Rewrite Questions