I want to use mod rewrite via htaccess for a PHP website.
The structure of the URL is as follows:
example.com/ex.php?ez=DF004AE
He must become:
example.com/ex/DF004AE.htm
What is the correct script to add to my .htaccess for this?
Use this:
RewriteEngine On RewriteRule ^ex/([^/]*)\.htm$ /ex.php?ez=$1 [L]
It will provide you with the following URL:
If you meant this .html (not.htm) Just add l to the RewriteRule.
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 converts /ex.php?ez=foobarto /ex/foobar.htm.
/ex.php?ez=foobar
/ex/foobar.htm
RewriteEngine On RewriteRule ^ex/([^/]*)\.html$ /ex.php?ez=$1 [R=301,NE,L]
If you do not want the address bar to reflect this change, delete R = 301. The NE parameter must ensure that the request is not escaped.