ahmad ali ahmad ali - 2 months ago 13
PHP Question

rewrite url www.xyz.com/index.php?id=xyz to www.xyz.com/xyz using htaccess

I want to include item details

details.php
if url has parameter
id=xyz


rewrite

url www.example.com/index.php?id=xyz


to

www.example.com/xyz.html


using
htaccess


htaccess i am using has

RewriteEngine On
RewriteBase /

RewriteRule ^([^.]+)\.html$ index.php?id=$1 [L,QSA,NC]

Answer
RewriteCond %{THE_REQUEST} \s/index\.php\?id=([_0-9a-zA-Z-]+)\s [NC]
RewriteRule ^%1? [R=301,L]
RewriteRule ^([_0-9a-zA-Z-]+)$ /index.php?id=$1 [L]

RewriteCond %{THE_REQUEST} \s/index\.php\?id=([_0-9a-zA-Z-]+)\s [NC]
RewriteRule ^ %1.html? [R=301,L]
RewriteRule ^([_0-9a-zA-Z-]+?)(?:\.html)?$ /index.php?id=$1 [NC,L]

worked perfect

Comments