RickGrimesLikesWalkerSoup RickGrimesLikesWalkerSoup - 1 year ago 97
HTML Question

HTML URL Path Rewriting

I am running static HTML files on a local MAMP server and I would like to pass an ID to a page (user.html) in the 'URL Path' format. Here's what I need it to look like:


  • user is the html page. I removed the .html extension from the url by using .htaccess rules

  • the number after the user/ is the ID parameter

  • john is another parameter I need to add to the url

This is what my .htaccess file looks like:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html

Currently the URL looks like this:


So I could send parameters as Query strings using
but I need to use the Path format

What is the change I need to make to create that URL Format?

Answer Source

You need add new rewrite rules to pass additional parameters to your pages:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^/]+)/?$ $1.html [L]

RewriteRule ^([\w-]+)/([\w-]+)/([\w-]+)/?$ $1.html?id=$1&name=$3 [L,QSA]

RewriteRule ^([\w-]+)/([\w-]+)/?$ $1.html?id=$1 [L,QSA]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download