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

Removing index.php from a URL path in XAMPP for Windows

STEP 1: Create .htaccess using the command prompt in Windows

  1. Open command prompt

  2. In the command prompt, change the working directory to the CodeIgniter directory i.e. the directory that contains the application and system directories

    cd C:\xampp\htdocs\site_folder

  3. Type copy con .htaccess to create a .htaccess file in the current working directory

  4. Press [ENTER] to append an empty line

  5. Type the following code:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
    </IfModule>
    
  6. Finally, enter CTRL + Z to append the data to the .htaccess file and hit [ENTER] to save

STEP 2: Configure mod_rewrite in httpd.conf

  1. Locate the httpd.conf file in the Apache sub-directory C:\xampp\apache\conf\httpd.conf

  2. Uncomment the following line from: #LoadModule rewrite_module modules/mod_rewrite.so

    to

    LoadModule rewrite_module modules/mod_rewrite.so

  3. Save the changes to the file

STEP 3: Configure config.php in you site_folder (CodeIgniter) folder

  1. Locate config.php C:\xampp\htdocs\site_folder\system\application\config

  2. Change the following line from: $config['index_page'] = 'index.php';

    to

    $config['index_page'] = '';

Redirect non www to www url

It is very important from SEO point of view for a site to open from single URL. If we want that uor site should only open with www preceding the url we should just copy and paste the code below in our .htaccess file and you are done.For example if a site opens with 'abc.com' and also with 'www.abc.com' and you want that it should always open with 'www.abc.com' and if one tries to open with 'abc.com' it should redirect it to 'www.abc.com'.

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

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