skip to Main Content

I have came accross a problem that every .htaccess query I’ve tried wasn’t worked out ! I have URLs like this:

And I want to change it to a user friendly URL like this:

Or it can be:

I’ve tried this code below:

RewriteEngine on
RewriteCond %{QUERY_STRING} ^x=product$
RewriteRule ^index.php.*$ [R=302,L]

Now, it is redirecting perfectly, but this is not the problem. I’ve used this for only SEO so I must include in the product.php file. Any help can be precious, thanks…



  1. You can use this code in your DOCUMENT_ROOT/.htaccess file:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{THE_REQUEST} /index.php?x=([^s&]+) [NC]
    RewriteRule ^ /%1/? [R=302,L,NE]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^/.]+)/?$ index.php?x=$1 [L,QSA]

    This will redirect /index.php?x=product to /product/ and will rewrite it internally to /index.php?x=product in 2nd rule.

    Login or Signup to reply.
  2. You don’t need to put anything in the product.php file. Make sure there is a .htaccess in the directory that has the files you want to make url/seo friendly.

    To have it SEO friendly make sure its in this format not
    if you must have a file extension, have it in (you want to tell the search engine the page isn’t dynamic although it is to get better pagerank)

    Insert this in your .htaccess

    RewriteRule /(.*)/$ products.php?x=$1

    the (.*) pulls the elements out and puts them in variables $1

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top