How to rewrite this url using htaccess?

I have this url, http://website.com/?slug=product_info.php&products_id=28

and wanted to rewrite it to:
http://website.com/page/product_info/product_id/28

Read More

How to do this using the htaccess or the function “wp_rewrite” of wordpress?

Thank you.

Related posts

Leave a Reply

1 comment

  1. In the .htaccess file you can try:

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^page/([^/]+)/([^/]+)/([0-9]+)/? /?slug=$1&$2=$3 [QSA,L]
    

    This will make it so when you type http://website.com/page/product_info/product_id/28 into your browser’s address bar, it gets rewritten internally on the server into /?slug=product_info.php&products_id=28.

    If you meant the other way around, the rewrite will look like this:

    RewriteCond %{QUERY_STRING} ^slug=([^&]+)&([^=]+)=([^&]+)
    RewriteRule . /page/%1/%2/%3 [L]
    

    So this will make it so when you type http://website.com/?slug=product_info.php&products_id=28 into your browser’s address bar, it gets rewritten internally on the server into /page/product_info/product_id/28.