I want to use mod rewrite via htaccess for a PHP website.
URL structure is the following:
example.com/ex.php?ez=DF004AE
It must become:
example.com/ex/DF004AE.htm
What is the correct script to add to my .htaccess in order to do that?
I want to use mod rewrite via htaccess for a PHP website.
URL structure is the following:
example.com/ex.php?ez=DF004AE
It must become:
example.com/ex/DF004AE.htm
What is the correct script to add to my .htaccess in order to do that?
You can use the following rules :
RewriteEngine on
# Redirect from "/ex.php?ez=foobar" to "/ex/foobar.htm"
RewriteCond %{THE_REQUEST} /ex\.php\?ez=([^\s]+) [NC]
RewriteRule ^ /ex/%1.htm? [L,R]
####################
# internally map "/ex/foobar.htm" to "/ex.php?ez=foobar"
RewriteRule ^ex/([^.]+)\.htm$ /ex.php?ez=$1 [NC,L]
This will convert /ex.php?ez=foobar into /ex/foobar.htm .
Use this:
RewriteEngine On
RewriteRule ^ex/([^/]*)\.htm$ /ex.php?ez=$1 [L]
It will give you the following URL:
example.com/ex/DF004AE.htm
If you meant it to be .html (not .htm) Just add the l in the RewriteRule.