HTACCESS Useful Rewrite Codes 2017 [Updated]

Aug 16

Hello Bloggers 🙂 Here i am talk about How you use htaccess codes to secure your website and do some easy things 😉 without using Plugins.Indirectly Htaccess editing  Speedup Your website :p Yes!! You Read right!! Reason is Simple – “Less WordPress Plugins” . You done same thing via Editing .htaccess so let’s to edit htaccess :p and secure and speedup your WordPress site.

 

How to Edit .Htaccess

 

First of all Login to your Cpanel after that go to File manager ( see below Screenshot )

You can Easily Edit this way.

 

Alternative way 

Yoast SEO Plugin Yoast SEO > Tools > File Editor


 Below I added  htaccess codes just applied with Proper way


Redirecting .html to non .html pages


RedirectMatch 301 ^/([^/]+)/([^/.]+).html$ /$1/$2/
RedirectMatch 301 ^/([^/]+)/([^/]+)/([^/.]+).html$ /$1/$2/$3/

 

SEO Friendly URL

NON-SEO Friendly URL – http://mantichost.com/post.php?id=45
SEO Friendly URL – http://mantichost.com/post-45.html


Options +FollowSymLinks
RewriteEngine On
RewriteRule ^article-([0-9]+)\.html$ post.php?id=$1

For Force HTTP


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} ^https$
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI}
</IfModule>

WWW to NON-WWW


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

For Force HTTP


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} ^https$
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI}
</IfModule>

Disable directory listing

 
Options -Indexes

 

Custom 404 Error Page


ErrorDocument 404 /404.html

For HTTPS Redirection


RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

301 Post Redirection

RewriteEngine On
Redirect 301 /blog-old-post/ http://www.example.com/my-blog-updated-post/

Thanks You to Reading and applying this method 🙂 Guys!! any Problem to edit htaccess File and If you know more htaccess codes  comment here.we update our post 😉

Visioned by a group of like minded thinkers, Mantic Labs was founded to reshape the whole Web Hosting and Digital Marketing Industry by providing Quality services at affordable prices by offering premium support.With an aim to turn the dreams of young business to reality, MantiLabs is culmination of Experience, Genius and Hard work.
Contact Us

First Floor 4 Indira Park Complex,
Opp. Iconic, Jodhpur Cross Road, Satellite,
Ahmedabad - 380015, Gujarat

Phone: +91 76989-16989

E-Mail:info@manticlabs.in