in Web and Tech

mod_rewrite: the Apache rewrite engine

It’s been a while since I had to tinker with Apache’s terrific rewrite engine – mod_rewrite. And again a time comes when I need to recall what I did to get something working on what seemed like ages ago. I look through the blog to search about this, and realize that I haven’t documented that. At least not here. Unfortunately, I cannot find it anywhere else, if ever I did document that. So I do some quick Google searches and manage to scrounge up what seem to be good resources on the topic. Some sites/pages I actually remember having visited.

Here are the links.

Introduction:
http://httpd.apache.org/docs/2.2/rewrite/intro.html

http://code.tutsplus.com/tutorials/an-in-depth-guide-to-mod_rewrite-for-apache--net-6708

http://www.branded3.com/blogs/htaccess-mod_rewrite-ultimate-guide/

Tips and Tricks:

http://www.askapache.com/htaccess/modrewrite-tips-tricks.html

Cheat sheet:
www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet.html

How to check if mod_rewrite is enabled:
http://www.wallpaperama.com/forums/how-to-test-check-if-mod-rewrite-is-enabled-t40.html

Code generator:
http://www.visiospark.com/mod-rewrite-rule-generator/

Write a Comment

Comment

  1. #Full example for a WordPress site.
    #Note that the rewrite condition and rules are outside the “# BEGIN WordPress” and “# END WordPress” to avoid being overwritten from within WordPress

    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
    RewriteCond %{HTTP_HOST} ^www.example.com
    RewriteRule (.*) http://example.com/$1 [R=301,L]
    RewriteRule ^shopper$ /contact-us? [L,R=301]

    # BEGIN WordPress

    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ – [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    # END WordPress

    # Source: https://help.dreamhost.com/hc/en-us/articles/215747758-Force-your-site-to-load-securely-with-an-htaccess-file