WPITECHWPITECH

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    12 Best Ecommerce Software in 2021 & in the Future

    July 31, 2021

    Why Is My Canon Printer Not Printing Properly?

    July 31, 2021

    5 Best Google Analytics Plugins

    May 28, 2021
    Facebook Twitter Instagram
    Facebook Twitter Instagram
    WPITECH WPITECH
    • Home
    • Tutorials
      • WordPress Tutorials
      • WordPress Plugin
      • WordPress Themes
      • WooCommerce
      • Ecommerce
      • PHP
    • Hosting
    • Deals
      • Hosting Deals
    • SEO TOOLS
      • Bulk Url Checker
      • Structured Data
      • Google Cache
      • Hyperlink Generator
      • Free URL Checker
    • Marketing
      • SEO
      • Advertising
    • Reviews
    • Write for Us
    • About Us
    WPITECHWPITECH
    Home » How To Create & Edit .htaccess File using Rewriterule
    WordPress Tutorials

    How To Create & Edit .htaccess File using Rewriterule

    WPITECHBy WPITECHMarch 22, 2019No Comments3 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email
    A-Complete-Guide-to-htaccess-file
    Share
    Facebook Twitter LinkedIn Pinterest Email

    Table of Content

    • What is htaccess file
    • Locating and Opening File Manager
    • Locating .htaccess file in File Manager
    • Creating .htaccess file if it is not present
    • Redirect everything the www subdomain
    • Redirect everything to HTTPS
    • PHP file to handle all non-static requests
    • Rewrite GET parameter to URL part

    What is htaccess file

    .htaccess is a hidden file that is used for your website’s configuration. Using it, you can protect password directories, do URL rewriting, disallow access to specific IP addresses, enable hotlink protection, change your website’s time zone or default index page and much more. This tutorial shows how to create .htaccess file by using File Manager in your hosting control panel.

    Steps to Follow

    Before you read this guide you’ll need the following:

    Where is htaccess

    Access to your hosting account’s control panel

    Step 1 — Locating and Opening File Manager

    Go to your hosting account’s control panel and open up the File Manager tool located in the Files category:

    File Manager Htaccess

    After clicking on the file manager you go to settings and check the show hidden file option.

    Domain Preferences

    Step 2 — Locating .htaccess file in File Manager

    .htaccess file is located in your public_html directory. You can easily access the file and it’s content by clicking and selecting Edit:

    .htaccess edit

    If your hosting platform uses cPanel, then the process is easy.

    edit Htaccess

    Step 3 — Creating .htaccess file if it is not present

    If there is no .htaccess file then create a new .htaccess file

    create htaccess

    After that, write the name .htaccess and press Create to save it. You will then be able to access your newly created file and put the code.

    Redirect to www subdomain

    This snippet redirects all non-www requests to the www subdomain

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

    Redirect to HTTPS

    This snippet redirects all non-HTTPS traffic to HTTPS

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

    PHP file to handle all non-static requests

    In PHP it allows you to read the actual requested path in the $_SERVER[‘REQUEST_URI’] global variable.

     RewriteEngine On
     RewriteCond %{REQUEST_FILENAME} !-d
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteRule ^(.*)$ index.php [QSA,L]
    

    Rewrite GET parameter to URL part

    If you have an URL that you want to call with “GET /orders?id=13” and you want it to respond as if “GET /orders/13” was called, then you may use the following snippet code

     RewriteEngine On
     RewriteCond %{REQUEST_URI} ^/orders [NC]
     RewriteCond %{QUERY_STRING} ^id=([0-9]+)$ [NC]
     RewriteRule ^(.*)$ %{REQUEST_URI}/%1\? [R,L]
    
    htaccess location htaccess redirect to www what is htaccess file where is htaccess
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    WPITECH

    Related Posts

    9 Amazing Benefits of Using WordPress for Your Projects

    May 15, 2021

    Must have Features for WordPress Website

    February 4, 2020

    WordPress vs Squarespace: Best Comparison 2020

    January 6, 2020
    Add A Comment

    Leave A Reply Cancel Reply

    You must be logged in to post a comment.

    Recent Posts
    • 12 Best Ecommerce Software in 2021 & in the Future
    • Why Is My Canon Printer Not Printing Properly?
    • 5 Best Google Analytics Plugins
    • 12 Best Email List Building Tools in 2021
    • 9 Amazing Benefits of Using WordPress for Your Projects
    Categories
    • Advertising (2)
    • Ecommerce (13)
    • Hosting (1)
    • Marketing (12)
    • PHP (3)
    • Reviews (4)
    • SEO (10)
    • Uncategorized (2)
    • WooCommerce (14)
    • WordPress Plugin (4)
    • WordPress Themes (1)
    • WordPress Tutorials (38)
    Editors Picks
    Top Reviews
    Advertisement
    Demo
    WPITECH
    Facebook Twitter Instagram Pinterest Vimeo YouTube
    • Home
    © 2023 All Rights Reserved.

    Type above and press Enter to search. Press Esc to cancel.