htaccess

April 28, 2012 Development no responses # , ,

301 .htaccess Redirect

To prevent getting 404 File Not Found error (traffic coming from links, bookmarks and search engines) when URLs and paths on site have changed, I use .htaccess 301 redirect. Htaccess redirect is better than the meta refresh or redirect tag because there is no delay as the browser reads the .htaccess file first. Here is how it works.

Go to your site’s root folder, download the .htaccess file to your local computer and edit it with a plain-text editor (ie. Notepad). If you are using FTP Client software and you don’t see any .htaccess file on your server, double check your setting and make sure you have turn on invisible / system files.

To Redirect Certain Page(s):

Redirect 301 /oldpage.html http://www.yoursite.com/newpage.html<br />
Redirect 301 /oldpage2.html http://www.yoursite.com/folder/<br />

To Redirect Entire Site:

Redirect 301 / http://www.new-site.com/<br />

Redirect with dynamic parameters

For example redirecting http://www.domain.com/brands/sony/sonys-new-s-frames-with-avchd-video-playback/ to http://www.domain.com/sony/sonys-new-s-frames-with-avchd-video-playback/

RewriteRule ^(.*)brands/([a-z_A-Z0-9\\-]+)/([a-z_A-Z0-9\\-]+)/$ http://%{HTTP_HOST}/$2/$3/ [R=301,L]
OR
RewriteRule ^(.*)([a-z_A-Z0-9\\-]+)/([a-z_A-Z0-9\\-]+)/([a-z_A-Z0-9\\-]+)/$ http://%{HTTP_HOST}/$2/$3/ [R=301,L]
December 13, 2011 How To's , SEO no responses #

301 Redirect from non-www to www

Do you want to improve your search engine rankings? SEO gurus told you that Google might be penalizing you for duplicate content? How did you get duplicate content, you ask? Unless you specify otherwise, we send www.yourdomain.com and yourdomain.com to the same place. Which is great because some clients automatically add a WWW to every url they type, and others almost never add www even if you tell them to. This way they end up at the correct page, regardless of what else they’ve included in their url.
The problem is that if people are linking to you sometimes with a www and sometimes without, spiders may think you’re trying to get away with publishing the same information twice. So some SEO experts have recommend you create a 301 redirect to send all non-www links to www.
You try it, and to your horror, the page now loops through so many redirect iterations that the site won’t display at all. Or, you try the common syntax and it messes up all your subdomains.
There is hope. Here is a 301 redirect syntax that does not loop, and does not affect your subdomains either.

Continue reading

November 20, 2011 How To's no responses # , ,

How to add expires header to images?

Caching with .htaccess and Apache will take your website and your web skills to the next level. This is some technical and advanced methods condensed to simple htaccess code examples for you. But you must take the time to understand caching with cache-control and other headers and HTTP options before you implement on a production server.

How to add expires header to images?
Continue reading

June 2, 2011 Wordpress no responses # ,

Remove /category/ from your WordPress url

If you wanted to be able to finally remove the useless /category/ from your WordPress categories permalinks? If yes, read on and get ready to hack your .htaccess file!

WordPress category permalinks are displayed that way:

  • http://www.domain.com/blog/category/wordpress

As you can see, the category in the url is pretty useless. Here’s how to remove it:

Continue reading

June 2, 2011 MySQL , Wordpress no responses # ,

Moving WordPress site to new domain

When You decide to reorganize the blog link URL to make it tidier or to reflect new focus or theme of the blog. If you decide to change the URL or link location of your WordPress blog due to changing of domain name (such as from http://www.old-domain.com/ to http://www.new-domain.com/) or the blog to another directory location (such as from http://www.domain.com/ to http://www.domain.com/blog/), there are some steps that should be done to ensure the proper migration and no breaking links.

The tricky part when moving WordPress blog to another location is that WordPress is using absolute path in URL link instead of relative path in URL link location when stores some parameters in database. Within blog posts’ contents itself, users may also use the old URLs when creating reference backlinks. All these values in the database will need to be changed when WordPress is moved. The following guide will show you which database fields that has references or values related to blog’s URLs that you want to modify. Note that this guide is not about how to move WordPress blog from one server or host to another new hosting service.
Continue reading

Pin It on Pinterest