Showing posts with label htaccess. Show all posts
Showing posts with label htaccess. Show all posts

Thursday, August 6, 2015

How to use .htaccess

How to use .htaccess 

I heard about the .htaccess file, but wondered what it was, or what, if anything, you can do with it. This tutorial will tell you the basics about .htaccess.


htaccess is short for Hypertext Access, and is a configuration file used by Apache-based web servers that controls the directory

Some of the features of the .htaccess file include the
  • redirect users to another page or directory automatically,
  • create and use custom error pages,
  • ability to password protect folders,
  • ban users or allow users using IP addresses,
  • stop directory listings,
  • change the way files with certain extensions are utilized, or even use a different file as the index file by specifying the file extension or specific file.


Custom Error Pages for Better SEO

One use of the .htaccess file is to redirect users to a custom error page depending on the specific web server error they encounter. By using a custom error page, you can present them with a list of your site's top articles, a sitemap with links to the various areas of your site, and it can include your site's navigation system. It can also feature a FAQ, so folks who are looking for information on your site, but can't find it, are able to narrow down the location of that information on your site without leaving, going back to the search engine, and more than likely not returning to your site.

It's not difficult to use the .htaccess file to redirect users to a custom error page--but to do it you'll need to know the proper error code. The most common ones you'll use are:

    400 - Bad request
    401 - Authorization Required
    403 - Forbidden
    404 - File Not Found
    500 - Internal Server Error

To use .htaccess with these codes, first you'll need to open up your favorite text editor, create a new document, and in that document, specify the error message that you'll be redirecting like this:

ErrorDocument 404 /filenotfound.html

If you wanted to redirect users for another error, such as 500, Internal Server Error, you would do it like this (and so on):

ErrorDocument 500 /servererror.html

Then you'd just save the .htaccess file (remembering to check that it is saved just like that, without some additional extension), and upload it to your web host's root directory (or whatever directory you are wanting to use it in).
Using a Different File as the Index File
By adding another "command" to the .htaccess file, you can use a different file as the main index file that folks see when they come to your site. In other words, when folks visit www.yoursite.com, usually they are presented with www.yoursite.com/index.html or www.yoursite.com/index.php--but often you have created a special page that you want to use as your site's main page--and it isn't any of the traditional pages. Or you may want to take advantage of the latest version of PHP...there are many reasons for needing to use a different file as the index file. Here's how you would do it, with each type of file being next in line, if the others are not in the directory.

DirectoryIndex index.php3 index.php pictures.pl index.html default.htm

For instance, if there was no file named index.php3 in your directory, then the server would look for a file called index.php. If that file wasn't present, it would look for one called pictures.pl, and so on.


Wednesday, July 22, 2015

Remove Index.php From URL in CodeIgniter

How To Remove Index.php From CodeIgniter in Windows Xampp

Follow This Step
1. First check mod_rewrite is enabled or not
2. To check this create php file type in that



3. Run into browser
4. Search for the mod_rewrite if you will find that in loaded module then its enabled else you have to enabled this mod_rewrite
5. After that create .htaccess file in your root folder of codeigniter
6. Copy this below codeand paste into that .htaccess file


7. After that change into the config.php of codeigniter

$config['index_page'] = 'index.php';    
    to      
 $config['index_page'] = ' ';                 

8. Here you done now run the file with index.php using url http://localhost/ci/welcome



-----------------------------------------------------------------------------------------------
you would also like 

 Interview Question [PHP] 

How to create JSON using MySql Database [PHP]




Saturday, May 9, 2015

.htaccess To Redirect URLs WWW

For SEO it is important to use a set standard of how you present your domain. The most popular approach is to use the sub-domain www. Many people don't know this but http://www.domain.com is the same as http://domain.com, you will be sent to the same page but they will have different URLs.

For SEO if a search engine saw http://www.domain.com it will crawl this page, check the content and index the content. Then later if it goes and crawls http://domain.com the search engines will see the same content but on different URLs and think it is duplicate content and therefore will penalize this domain in the search engine ranking.

.htaccess To Redirect URLs
To use htaccess to redirect URL just copy and paste the snippet below and replace example.com with your domain.

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

Add www With HTTP/HTTPS

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Tuesday, January 13, 2015

Enable htaccess in Apache 2.4.7 on Ubuntu

Enable htaccess in Apache 2.4.7 on Ubuntu

open terminal
ctrl+alt+t 
 open etc folder into this open apache2
etc->apache2->apache2.conf 
into this file 
  <Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride none
    Require all denied
</Directory>
<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
 
First enable rewrite using this command:
sudo a2enmod rewrite
Then restart apache2:
sudo service apache2 restart 
Enjoy :) 

How to Host a Laravel Project on Hostinger’s hPanel: A Step-by-Step Guide

How to Host a Laravel Project on Hostinger’s hPanel: A Step-by-Step Guide If you're looking to host a Laravel project on Hostinger’s hPa...