Redirect folder to new domain

How do you redirect a folder to a new domain?

Here is a working example that we have in use for this very same change you may need to make.

This code is to be placed in your .htaccess file. If you do not know what you are doing, you could cause your site to 500 page error by simple typos. Please refer this page to your site’s developer or programmer.

WARNING. Improper use of htaccess or simple typo can render your site broken / inoperable. Don’t scream at your neighbor if you forget to make a backup of your file. Then, if things go wrong, you can just upload your original .htaccess file to the server. Backups are important, you have been politely warned.

##  top of htaccess:
RewriteEngine On
Options +FollowSymLinks

# first lets normalize our URL so that non www redirects to www
RewriteCond %{HTTP_HOST} ^m3server\.com$ [NC]
RewriteRule ^(.*)$ http://www.m3server.com/$1 [R=301,L]

#  our blog directory has moved to it's own site.  let's redirect it.
RewriteRule ^blog(.*)$ http://blog.m3server.com$1 [R=301,L]

#   end of primary redirect

Note: Replace our domain name with your domain name and our directory with your directory. This is an example only.

You can test this like so:

http://m3server.com/blog

http://m3server.com/blog/hi.text

http://www.m3server.com/blog/hi.text

cache control

Setting long cache times results in less load on your server/site and less bandwidth. Better caching results in faster page load times and better google page scores.

If you don’t set your cache control, you basically let the brower/proxy/cdn determine these values for you. The following is an example of setting up cache controls for various file types. Please understand these are examples only. They are not intended to be illustrate the best optimizations for your site. Research first and get a better understanding before applying these very useful tools and how your site can benefit.

This code is to be placed in your .htaccess file. If you do not know what you are doing, you could cause your site to 500 page error by simple typos. Please refer this page to your site’s developer or programmer.

WARNING. Improper use of htaccess or simple typo can render your site broken / inoperable. Don’t scream at your neighbor if you forget to make a backup of your file. Then, if things go wrong, you can just upload your original .htaccess file to the server. Backups are important, you have been politely warned.

<ifModule mod_headers.c>
ExpiresActive On

# Expires after 2 hours
<filesMatch ".(gif|png|jpg|jpeg|ico|pdf|js|flv|swf)$">
Header set Cache-Control "max-age=7200"
</filesMatch>

# Expires after 300 seconds
<filesMatch ".(css|htm|html)$">
Header set Cache-Control "max-age=300"
</filesMatch>

# No caching
<filesMatch ".(php|shtml)$">
        Header unset ETag
        Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
        Header set Pragma "no-cache"
</filesMatch>

</ifModule>

# Set a short cache time for a rapidly updated file or file in development

<Files tools.php>
  ExpiresDefault "access plus 20 seconds"
</Files>

Remember, setting the times for as long as possible results in resource consumption on your server. However, if you are editing common files frequently, you may wish to have a lower time for those files. If your files rarely change, setting the max age to a week or a month is advisable.

set timezone per site

Advanced method, use php:
php.net manualtimezone

Easy method, use htaccess.
Objective: Set tiemzone

Scenarios:

  • How to use a different timezone per site
  • Set your site to work in your timezone VS the local server time

WARNING. Improper use of htaccess or simple typo can render your site broken / inoperable. Don’t scream at your neighbor if you forget to make a backup of your file. Then, if things go wrong, you can just upload your original .htaccess file to the server. Backups are important, you have been politely warned.

Place this code at the top of your htaccess file:

php_value date.timezone "Europe/Istanbul"

Imagick PHP test code

Want to test Imagick in your php scripts?  Save this file as imagick_test.php and upload it to your server:

You will need to create a directory named test and chmod that to 777 so the script can write to it.

<?php

echo "Using convert:<br>";
$array = array();
/*  Replace test.jpg with the name of a jpg image in the same folder as this code and run it. */
/*  Note, the output is placed in a directory named test. If it doesn't exist, create it and chmod it to 777 for writing. */

exec("convert test.jpg -thumbnail 50x50 test/output2.jpg 2>&1", $array);
print_r( $array );

echo "Using /usr/local/bin/convert:<br>";
$array = array();
?>

In the event of line wraps viewing this page, please see the raw source here:
imagick_test.php

While programming is beyond the scope of technical support, this test page exists as a troubleshooting step. If this test script works but your application doesn’t, contact your software vendor’s support and show them your test example that you used via this article.

More examples are found here:
php.net imagick

WordPress Security Protect wp-content

Protect the security risk of your site’s /wp-content directory quickly and easily.

This is considered an advanced security filter, use it at your own risk. Please test your site completely before walking away. You have been politely warned.

WordPress holds all your site’s media files in wp-content directory. Although they are an asset you want search engines to index. But, “/wp-content” is the location of themes and plugins too. You don’t want to allow access to those sensitive .php files or allow malware to be be accessed if infected.

Use your FTP client and create a file without a name and give it the extension, .htaccess. Now upload it to your /wp-content directory. This code will allow access to images, CSS, java-script and XML files, but deny it for any other type, including malicious scripts such as php scripts (often found in untrusted plugins).

Notice: Check your web site’s operation after this simple modification.  We have seen some 3rd party themes/plugins require access.

Using your browsers developer features, you can inspect to see if you are blocking any content that should be allowed. In the example below, you will notice that I am allowing wp-spamfree to pass my security filter..

order deny,allow
deny from all
<files ~ "(.(xml|css|jpe?g|png|gif|js)|((wpsf-img|wpsfv2-js).php))$">
allow from all
</files>
</files>

WordPress Auto Update – M3 5 Series

Ready to update your WordPress instance but unsure what to do?

No problem, just follow this simple guide to get your next update done quickly and easily.

WARNING:   Do not complete this without first getting a new backup of your site files AND most importantly, your database.  I cannot stress this enough.  If your site’s contents are vital to you and your operation,  do not trust the upgrade process – GET YOUR BACKUPS FIRST.

Let’s get to the upgrade shall we, follow these steps:

  • login to your wp-admin dashboard.
  • click on updates or upgrade now at the top center of your dashboard.

Dashboard updates location:

  1. server name, enter localhost
  2. user name, just the ftp user name, not your email address
  3. your ftp user name’s password
  4. select FTPS (SSL)
  5. click proceed

Update WordPress credentials menu:

Why enter credentials?  This is because the site runs as the apache user, safest for security.  This is the most secure and preferred method of running a WordPress instance.

Follow the prompts, and be patient.  Depending on your server load, content size, this could take a few minutes.  If WordPress instructs you to upgrade your database, you must.

- M3Server Inc Managed VPS Hosting

Create Database backup with phpmyadmin

Creating a backup of your database is very important.  Besides having a safe and updated copy of your database, its also wise to do so before upgrading wordpress or any other major changes.  While there are a few methods for doing so, this how to will cover the topic of phpmyadmin.  PhpMyAdmin is a tool to manage your database, it can also be used to export your database to a backup file for safe keeping.

1) login to your phpmyadmin URL.  What is your URL?  It will look something like this, just use your server name instead of example:

https://SERVER_NAME.SOME_HOST.net/phpmyadmin/

The user name and password is of the database you wish to manage.  If you don’t remember it, just look inside your php config file for the settings.  The php config file for wordpress is, wp-config.php.

2) Once logged in, you will notice a row of tabs on the top.

first

Click on the Export tab and follow the steps:

  1. Select only your database, not al
  2. l.Screen Shot 2013-08-28 at 9.46.21 AM
  3. Ensure SQL is selected under Export section
  4. If your database is large, I suggest you use one of the Compression options.
  5. Ensure the box is checked “Safe as file”
  6. Screen Shot 2013-08-28 at 9.48.00 AM
  7. Enter the db name in the “File name template” box.
  8. click Go (bottom right)
  9. Depending on your browser or operating system, your file will be downloaded into the browsers default location, or you may be prompted to save as.

Enjoy your backup!

Note:  If you have other databases, you will need to log out of phpmyadmin, then log back in with the other database user name and password.  Repeat this for each database that you have.

You don’t ever have to import your database (restore) unless your current database breaks or is corrupt.

If you have many databases, please contact support and we can script this backup process for you.  You can then download them via FTP at your leisure.