Enable rewrite by .htaccess

Enabling Rewrite by .htaccess

To enable rewrite by .htaccess put this in htaccess file


<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

Redirect everything the www subdomain


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

Redirect everything to HTTPS


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

PHP file to handle all non-static requests


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

Note that the PHP file is bypassed for existing files (static content).

Rewrite GET parameter to URL part


<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^/orders [NC]
    RewriteCond %{QUERY_STRING} ^id=([0-9]+)$ [NC]
    RewriteRule ^(.*)$ %{REQUEST_URI}/%1\? [R,L]
</IfModule>

8 thoughts on “Enable rewrite by .htaccess

  • September 27, 2016 at 12:23 am
    Permalink

    Right here is the perfect web site for anybody who wishes to understand this topic.

    You understand a whole lot its almost hard to argue with you
    (not that I actually would want to…HaHa). You definitely
    put a brand new spin on a subject that has been discussed for many years.
    Excellent stuff, just great!

    Reply
  • September 27, 2016 at 6:12 am
    Permalink

    Great blog here! Also your web site rather a lot up very fast!

    What host are you the use of? Can I get your associate hyperlink in your host?

    I wish my web site loaded up as fast as yours lol

    Reply
    • September 27, 2016 at 6:56 am
      Permalink

      i use gulp to speed up please read gulp section and implement it on yours 🙂

      Reply
  • September 29, 2016 at 10:50 am
    Permalink

    Its not my first time to go to see this site, i am visiting this web site dailly and take fastidious
    data from here daily.

    Reply
    • September 29, 2016 at 10:55 am
      Permalink

      Thanks buddy, please try to share it also so that it get more popular.

      Reply
  • October 4, 2016 at 9:52 pm
    Permalink

    This is my first time pay a visit at here and i am really pleassant to read everthing
    at one place.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *