Abu Ayyub Abu Ayyub - 4 years ago 203
PHP Question

change original URL to pretty URL with .htaccess file

I am trying to create pretty URL from my site, but I still newbie in .htaccess, I am so confuse to do it.

Original URL:

1. mysite.com/index.php?mode=frontend&act=viewArtikel&cat=hotnews&year=2017&month=02&link=hello-world

2. mysite.com/index.php?mode=frontend&act=viewProduct&cat=food&link=pizza


Expected:

1. mysite.com/hotnews/2017/02/hello-world.html
2. mysite.com/food/pizza.html


How to do it?
Thanks in advance
ps: please don't mark this post duplicate, sorry for my bad English

Answer Source

Try below rule,

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([\w-]+)/([\d]{4}+)/([\d]{2}+)/([\w-]+)\.html$ index.php?mode=frontend&act=viewArtikel&cat=$1&year=$2&month=$3&link=$4 [L]
RewriteRule ^([\w-]+)/([\w-]+)\.html$ index.php?mode=frontend&act=viewProduct&cat=$1&link=$2 [L]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download