Search code examples
.htaccessmod-rewrite

mod_rewrite static URL to dynamic


How to rewrite this URL

http://www.domain.com/folder/number/50.html

to

http://www.domain.com/folder/number?id=50#50

Appreciate your help.


Solution

  • You may try this in the .htaccess file in root directory:

    Options +FollowSymlinks -MultiViews
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^folder/number/([^/]+)\.html/?  /folder/number?id=$1#$1  [NE,NC,L]
    

    Map silently

    http://www.domain.com/folder/number/50.html with or without trailing slash

    To:

    http://www.domain.com/folder/number?id=50#50

    String 50 is assumed to be dynamic.

    For permanent and visible redirection, replace [NE,NC,L] with [R=301,NE,NC,L]