1

i created a php website and i got my 1 problem which is remove the query string in the URL using htaccess.

Host Directory from public_html

  • index.php
  • product.php

In the index.php i put a link on a query from database

<a href="product.php?id=<?php echo $row['P_ID']; ?><?php echo $row['P_ID']; ?></a>

It will redirect in product.php to show the specific product, let just say you select or click product id 100 it will show the details of that product id. and the URL is www.mysite.com/product.php?id=100.

In the product.php i used the code <?php $pid = intval($_GET['id']); ?> to get the details of the specific product in the product.php page.

I want to remove my query string in the URL using .htaccess with the following code RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)/?$ product.php?id=$1

But it doesn't help me to remove the query string. I want my URL clean for sql injection attack. So it would be look like this after the query string clean www.mysite.com/product/100

I need help for this in advanced.

1 Answers1

0

it's simple, just use:

RewriteCond %{QUERY_STRING} "post_type=" [NC]

RewriteRule (.*) /$1? [R=301,L]

If you are going add this to wordpress website, you need add it before any wordpress rules:

RewriteRule ^index.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L]

but after

RewriteBase/

  • RewriteBase / RewriteEngine On RewriteCond %{QUERY_STRING} "id=" [NC] RewriteRule (.*) /$1? [R=301,L] it remove the ?id= it appear only product.php and there is no record if i like one product to show like the product which has 100 id. if i click it will redirect www.mysite.com/product.php it not display the product 100 because the is now undefine – Richard Flores Jun 06 '16 at 08:12
  • @Aniruddh Sinh Dhummad : You have just copied and pasted [this](http://stackoverflow.com/questions/14071671/remove-query-string-from-end-of-url-url-using-htaccess#answer-14083186) answer – Alpesh Trivedi Mar 16 '17 at 06:43