Htaccess Guide

What is Htaccess ?

Htaccess Basics

  • Most rules are composed of 'function''regex condition''action' . For example

    • RewriteRule ^index\.php$ other-file.php [L] redirects quries from index.php/ to other-dile.php, both relative to document root.

Code Samples

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~michael/wordpress/wp1/

RewriteCond %{REQUEST_URI} ^(.*)TextToCheckFor(.*)?$
RewriteCond %{QUERY_STRING} ^.*parameter=argument.*$
RewriteRule ^(.*)$ – [R=403,L]

# Simple redirects
Redirect 301 /root-relative-path/ /new-root-relative-path
Redirect 301 /root-relative-path/ https://example/new-path/


# Redirect to new path & use regex group capture to pass on information to the new path .
RewriteRule /old-directory/(.*)$ /new-directory/$1 [R=301,L]


</IfModule>