HTACCESS useful Rewrite Codes 2017


HTACCESS useful Rewrite Codes 2017 - For Apache Web servers

For Force HTTP

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


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


RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$$1 [R,L]

Disable directory listing

Options -Indexes

Custom 404 Error Page

ErrorDocument 404 /404.html

For HTTPS Redirection

SEO Friendly URL

NON-SEO Friendly URL -
SEO Friendly URL -

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

Redirecting .html to non .html pages

Redirect subdomain from www to non-www

#Force non-www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$$1 [L,R=301]

301 Post Redirection

RewriteEngine On
Redirect 301 /blog-old-post/

SEO Friendly Profile URL to

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?user=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?user=$1

Bookmark This post I will Update New working Codes soon :slight_smile:


How to fix redirecting and Indexing both www and non-www versions?
Simple PHP URL Shortener Plugin :zap:

Awesome share bro, all these codes are very helpful during our blogging journey… permalink structure change, https SSL upgrade, etc.


yes bro, I will update More Working Codes soon :blush: bro

Useful Code Snippets and Functions For your WordPress Site :tada:

I can’t find File Upload in Yoast SEO-Tools.(Advanced is enabled)
Please Refer:


Goto tools - File Editor :pencil2:


I can see Bulk Editor & Import & Export…Nothing else.


You’ll have the “.htaccess” and “robots.txt” file editor section bro…