.htaccess

htaccess Redirecting non-www to www with .htaccess

If you want to redirect all non-www requests to your site to the www version, all you need to do is add the following code to your .htaccess file:
in your .htaccess file

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

This will redirect any requests to http://my-domain.com to http://www.my-domain.com. There are several benefits from doing that:

* It will avoid duplicate content in Google
* It will avoid the possibility of split page rank and/or split link popularity (inbound links).
* It’s nicer, and more consistent.

Note that if your site has already been indexed by Google without the www, this might cause unwanted side effects, like lost of PR. I don’t think this would happen, or in any case it would be a temporary issue (we are doing a permanent redirect, 301, so Google should transfer all rankings to the www version). But anyway, use at your own risk!

Something nice about the code above is that you can use it for any website, since it doesn’t include the actual domain name.
Redirecting www to non-www

If you want to do the opposite, the code is very similar:
in your .htaccess file

RewriteEngine On
RewriteCond %{HTTP_HOST} !^my-domain\.com$ [NC]
RewriteRule ^(.*)$ http://my-domain.com/$1 [R=301,L]

In this case we are explicitly typing the domain name. I’m sure it’s possible to do it in a generic way, but I haven’t had the time to work one out and test it. So remember to change ‘my-domain’ with your domain name! More >

friendly url with htaccess

suppose you want /articles.php?cat=$1&art=$2 to become magazine/1/2

then you need these two rules:

#articles.php?cat=$1&art=$2
RewriteRule ^magazine/([^/]*)/([^/]*)$ /articles.php?cat=$1&art=$2&marker [L]

RewriteCond %{REQUEST_URI} /articles\.php [NC]
RewriteCond %{QUERY_STRING} ^cat=(.*)&art=(.*)
RewriteCond %{QUERY_STRING} !marker

RewriteRule (.*) http://mydomain/%1/%2? [R=301,L]

Top 5 Online .htaccess Mod Rewrite Rules Generator

You might be aware of mod_rewrite rule and .htaccess file if you are using wordpress as your Blogging platform, .htaccess is the apache’s default directory level configuration files which can be used to password protect and redirect requests. Webmasters need to give special attentions to .htaccess on apache webserver as its very difficult to enforce all policies using just httpd.conf file. More >

.htaccess upload_max_filesize ini_set()

I m PHP 5.2.0 / Apache
and I can’t access php.ini

I try to update .htaccess
and added
php_value upload_max_filesize “25M”
php_value post_max_size “25M”

However it will give me “Internal Server Error” More >

Add Trailing Slash to the End of the URL with .htaccess Rewrite Rules

For a website that has URLs that end with a slash (/), it’s a good practice to ensure that all url links been parsed by the web server ended with trailing slash, even if visitors forget to enter the ending slash. This avoid visitors been served with 404 Page Not Found or Page Cannot be Displayed error as some webservers treat links without trailing slash as a file name instead of directory, and thus unable to locate the documents. It also eliminates the possibility that both pages with same content, one with slash at the end and another without, been viewed by search engines as duplicate content.

As an example, all hits to http://www.mydigitallife.info/contact should be redirect to http://www.mydigitallife.info/contact/. More >

Password Protecting Your Pages with htaccess

Creating the password file

The first step is to create a simple text file that will store your username and password, separated by a colon (:). The small catch is that the password must be encrypted. Luckily, there are many free web-based utilities that will encrypt the password for you. Try one of these:

Simply enter your desired username and password in one of these pages and submit the form. You’ll get back a string similar to the following: More >

Php, MySql, .htaccess: friendly urls

Php, MySql, .htaccess: friendly urls

There are a lot of tutorials that show how to change an address like:

  • www.mysite.com/products.php?product_id=1234

into others like:

  • www.mysite.com/products/1234
  • www.mysite.com/products/1234.html

In this article I’d like to go one step forward and to create something like:

  • www.mysite.com/easy-to-remember-product-name
  • www.mysite.com/easy-to-remember-product-name.html More >

.htaccess Generator

.htaccess File Wizard
The .htaccess is a simple method that allows you to customise the way the webserver works on a per directory basis. The .htaccess file is a simple ASCII text file, which when placed in a certain directory in your webspace, will cause the webserver to use that configuration on all files in that directory and any files in any subdirectories. 

When you have finished creating your .htaccess code, click on the “Select All” button and copy (CTRL + C) and paste (CTRL + V) the code into a text editor and save the file as .htaccess. The .htaccess file should have the name “.htaccess” (all lowercase), and can either be created using a command line text editor when logged in using ssh or can be uploaded by ftp. 

more info