Redirect certain pages from http to https with .htaccess


The following trick is useful for E-Commerce sites.  We only need few pages redirected to https to secure transaction
This will automatically rewrite the url to https as long as the page is not already an https link. This conditional keeps it from causing a loop.
It’s very handy to have this capabilit thus allowing you to designate any page you want to be loaded with SSL security. Even if you type it without https.


RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^shop/(.*) <a href="https://%25/" rel="nofollow">https://%</a>{HTTP_HOST}/shop/$1 [R=301,L]

Note: change shop to your (e-commerce/forms) directory name. If you are using WordPress Permalinks, change shop to the parent page

Moving WordPress blog from a subdomain to a subfolder

I had this blog and this main site on same domain, pixert.com a year ago. I got high traffic to same domain.

I separated the blog from main site after serious problems occurred. I made blog.pixert.com for blog and pixert.com for main site
That’s a mistake I should  not done.

Most startups have their blog on a separate sub domain like blog.pixert.com or blog.[your_domain].com
The thought of we could optimize it for SEO through the sub domain was wrong.
The traffic to the blog and the site lower than it was on same domain, pixert.com.

I decided to merge blog.pixert.com to pixert.com, I’m moving the blog to pixert.com/blog or [your_domain].com/blog .
It’s a delicate process to move blog.pixert.com to pixert.com. My concern in traffic from Google, the old URLs redirect to the new site

1. Disable a Caching plugin installed on the site
Delete the cache and disable that plugin

2. Change WordPress address (URL) and Site address (URL)
I change  WordPress address (URL) and Site address (URL) from blog.pixert.com to pixert.com/blog. This is a simply a matter of updating WordPress address and Blog address options from within the WordPress administration panel (Settings ->General)

3. Update Permalink structure.
Don’t forget to save Permalinks once more to make sure your WordPress site run smoothly. No need to change settings if you want to keep up same settings

3. Change Sub Domain root in cPanel
I created the blog subfolder in cPanel. The blog sub domain maps to a directory in the webroot called /blog/, however this directory been used by the new URL, pixert.com/blog.
I change the document root so I can apply redirection. If someone visits a link to a page that includes the sub domain, the web server will tell the browser that new site.

4. Redirect old URLs to the new URL via .htaccess
Create new .htaccess on new Sub Ddomain root, add the following

<pre>Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^blog.your_domain.com [nc]
rewriterule ^(.*)$ http://www.your_domain.com/blog/$1 [r=301,nc]</pre>

If someone tries to visit, http://blog.pixert.com/web-page-compression-enable-gzip-encoding-and-caching/, the server will (301) redirect to http://pixert.com/blog/web-page-compression-enable-gzip-encoding-and-caching/

5. Remove the old blog subdomain from Google Webmaster Tools
6. Submit all sitemaps from new URL through [your_domain].com account to Google using Google Webmaster Tools.

Web Page Compression: Enable gzip Encoding and Caching

Website load is one factor Google been considered to rank websites in their search engine. The next tutorial explain a step to improve loading time in your website. This step is focusing on gzip encoding and caching, it compress the content from your server to the client browser. The reduced file size is what speeds up loading time. We can use one of three ways to enable gzip encoding, php.ini, .htacess and using PHP.

You would want to check if GZip is enabled on your site using an online tool at GidZip Test. . If you see “NO” for “Web Page compressed?”, then gzip encoding is NOT enabled for your website

1. We can apply gzip compression on Apache level or Server level, simply add the following line anywhere: zlib.output_compression = on. 

2. If you want to apply gzip compresion on certain directory in your server, put the following in .htaccess file

<IfModule mod_deflate.c>
 AddOutputFilterByType DEFLATE text/html text/xml text/css text/plain
 AddOutputFilterByType DEFLATE image/svg+xml application/xhtml+xml application/xml
 AddOutputFilterByType DEFLATE application/rdf+xml application/rss+xml application/atom+xml
 AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript
 AddOutputFilterByType DEFLATE application/x-font-ttf application/x-font-otf
 AddOutputFilterByType DEFLATE font/truetype font/opentype
</IfModule>

3. You have WordPress installation. Download your WordPress index.php file from your server root directory. Open it up using your favorite PHP editor. Add the following  line just below  top php:

ob_start("ob_gzhandler");

This method requires you to  manually add that line again after a WordPress upgrade to enable gzip encoding. When upgrading your WordPress, the line you added,

ob_start("ob_gzhandler"); 

will be removed from index.php

Hide the Apache Web Server Version number


There are two config directives that controls Apache version.

The ServerSignature directive adds a line containing the Apache HTTP Server server version and the ServerName to any server-generated documents, such as error messages sent back to clients.

The ServerTokens directive controls whether Server response header field which is sent back to clients includes a description of the generic OS-type of the server as well as information about compiled-in modules.

Add the following to .htaccess

ServerSignature Off
ServerTokens Prod