How to do mod rewrite to covert dynamic url to seo friendly url?

Posted on 2012-08-21
Last Modified: 2012-08-22
Question by:melwong
    LVL 16

    Accepted Solution

    Create an .htaccess file as follows:

    Option 1 - literal translation of "es"

    Options +FollowSymlinks
    RewriteEngine On
    RewriteRule ^/?es$ /index.php?lang=$1 [NC]
    RewriteRule ^/?es/$ /index.php?lang=$1 [L,NC]

    Open in new window

    Option 2 - translation of lower case characters to a language variable

    Options +FollowSymlinks
    RewriteEngine On
    RewriteRule ^/?([a-z_]+)$ /index.php?lang=$1 [NC]
    RewriteRule ^/?([a-z_]+)/$ /index.php?lang=$1 [L,NC]

    Open in new window

    Generally you would be safer to define explicitly your available language options (as in Option 1) as this will help reduce the chance of malicious attempts to break your website.

    You can add more lines to your .htaccess to accomodate the extra langauges

    Author Closing Comment


    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    These days socially coordinated efforts have turned into a critical requirement for enterprises.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now