In your .htaccess file, replace “prolificfutility.com” with your own website.

The second set of rewrite conditions will allow search engines to crawl your site but redirect other requests from external sites to a single image or feel free to redirect them to another site!


<IfModule mod_rewrite.c>

#  Force www in website address
RewriteCond %{HTTP_HOST} ^prolificfutility.com
RewriteRule (.*) http://www.prolificfutility.com/$1 [R=301,L]

# Prevent hotlinking and bandwidth stealing:
RewriteCond %{HTTP_REFERER} !^http://([^.]+.)?prolificfutility.com[NC]
RewriteCond %{HTTP_REFERER} !google. [NC]
RewriteCond %{HTTP_REFERER} !search?q=cache [NC]
RewriteCond %{HTTP_REFERER} !msn. [NC]
RewriteCond %{HTTP_REFERER} !yahoo. [NC]
RewriteCond %{REQUEST_URI} !^/hotlink.gif$

RewriteRule .(gif|jpg|png)$ /hotlink.gif [NC,L]

</IfModule>

 


If you just want to redirect an individual page, set the rewrite rules below by replacing “page1” with the page your want to redirect to, in this case it is “new-page1”. The “page1” on the left can be COMPLETELY DIFFERENT than the destination file, by the way!

Do you see the pattern? Notice the (.*) wildcard, which represents a section of the page URL that can contain any characters as long as it is AFTER “page1” and the “$1” at the end of the new destination URL is the correlating reference to this wildcard text which essentially just carries the contents of text within this wildcard to its new place in the new URL on the right. Confused yet?!



RewriteEngine On
RewriteRule ^page1(.*) http://%{SERVER_NAME}/new-page1$1 [R,L]



These are snippets for your .htaccess file, comments are after the # hash tags and explain what each snippet does.

Replace “yoursite.com” with your actual website, of course!


# www on all URLs.
RewriteCond %{HTTP_HOST} ^yoursite.com [NC]
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [L,R=301]
 
# Switch to HTTPS version of the site.
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
 
# Ensure all web addresses have a trailing slash.
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.yoursite.com/$1/ [L,R=301]

The “L” in the square brackets tells the server if your rule is fulfilled with a match that is the “Last” directive to follow. The “R” stands for “Redirect” and allows you the option of defining what kind of redirect, typically, this is a 301 Permanent Move.


These are pretty standard settings, simply lines entered in your site’s root .htaccess file.  Be careful modifying your .htaccess file, if you don’t know what you’re doing a rogue semi-colon (;) could easily take your site down and throw that dreaded “500 Server Error” — that’s not the kind of error you want your website to get, but even though a 500 error looks bad, it’s amazing how you can bring a site down so easily with a simple character or a single line of code in many types of scripts.

An “.htaccess” file isn’t really a script, though it can contain behaviors and conditions, it’s more a set of directives that let the server know what you want it to do and how it can act.  Since it’s so powerful and does so much, with great power comes even greater responsibility. Keep in mind that you should be testing these directives on a “dev” server (development server) and not your live site!  Also these lines are generally accepted, but your flavor of Linux might require a different approach or modifying the settings and commands to work properly on your particular server.


<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

#Gzip
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript text/javascript
</ifmodule>
#End Gzip

# More optimizing

# BEGIN Expire headers
<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 5 seconds"
ExpiresByType image/x-icon "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 216000 seconds"
ExpiresByType application/javascript "access plus 216000 seconds"
ExpiresByType application/x-javascript "access plus 216000 seconds"
ExpiresByType text/html "access plus 600 seconds"
ExpiresByType application/xhtml+xml "access plus 600 seconds"
</ifModule>
# END Expire headers

# BEGIN Cache-Control Headers
<ifModule mod_headers.c>
<filesMatch "\.(ico|jpe?g|png|gif|swf)$">
Header set Cache-Control "public"
</filesMatch>
<filesMatch "\.(css)$">
Header set Cache-Control "public"
</filesMatch>
<filesMatch "\.(js)$">
Header set Cache-Control "private"
</filesMatch>
<filesMatch "\.(x?html?|php)$">
Header set Cache-Control "private, must-revalidate"
</filesMatch>
</ifModule>
# END Cache-Control Headers


Moving from Joomla to WordPress can be easy with a little planning.  One problem is the “legacy” links from Joomla that aren’t so search engine friendly.  When migrating to your new site, there are a lot of old links still out there.  You don’t want to frustrate your visitors with 404 “page not found” errors just because the old Joomla organization and page URLs were different.  With two lines of code, you can drastically reduce your 404 errors and keep everyone happy.  You will have to alter your .htaccess rewrite rules but hopefully you can pick up on the general pattern set below and find ways to accommodate as many old links into the new site as possible.

Put this code into your .htaccess file, you may have to change the /(.*)/ folders or some other logic based on how your old Joomla site was organized, but this worked great to help maintain old links out there, improving our site’s performance, customer satisfaction AND SEO rankings.  Keep in mind that the # hashtags in .htaccess files are comments and don’t do anything.

Basically, this rewrite ignores all the extra paths and query variables inbetween the actual link between your Joomla articles and your new site.  As long as your url (slug) for an article remains the same, an exact match on your new website will be found.  This works for WordPress and Drupal as well.  Migration and maintaining the integrity of your old website’s legacy links is a vital strategy to ensure you won’t lose visitors, followers and fans all while keeping the search engines happy.  Some pages you may still have to manually create rewrite rules or even redirect visitors, but with these two rewrite rules, you are taking care of probably 90% of old links if you are moving from Joomla to WordPress.  Too many rewrite rules in .htaccess can increase lag times, so it’s best to find the most efficient way to accomplish accommodating your legacy links.


#    /News/news-by-id-handler-maybe-old-joomla-articles.php?id=14703&catid=1&title=article-title-here
#    RewriteRule ^News/news-by-id-handler-maybe-old-joomla-articles.php?id=([0-9])&catid=([0-9])&title=(.*)/$   /$3 [R=301,L,NC]

RewriteCond %{THE_REQUEST} /News/news-by-id-handler-maybe-old-joomla-articles.php\?id=([^&amp;]+)&catid=([^\s&]+)&title=([^\s&]+) [NC]
RewriteRule  ^  /%3? [R=301,L,NC]

#Old Joomla articles:  /News/99999/999/article-title-here/
RewriteRule ^News/(.*)/(.*)/(.*)/$   /$3 [R=301,L,NC,QSA]