user1829823
user1829823

Reputation: 375

RewriteCondition hide the query string

I am trying to hide the query string that is in the URL.

cerberlus.com/review.php?id=Christopher%20Nolan%20

I have tried a few Rewrite Conditions but none work, however this is my first attempt at this procedure.

Any help would be greatly appreciated.

This is how the data is being displayed.

<div id="sub_review_container"> <? echo ($_GET['title'])?></div>
<div id="Review_container"> <? echo ($_GET['id'])?> </div>

This is how it is being sent:

<td align="left"><a href="review.php?id='. $row['review'] . '&title=' . $row['movie_title']  .'"> Read Review </a>

Upvotes: 1

Views: 63

Answers (2)

Jon Lin
Jon Lin

Reputation: 143966

To prevent people from editing the contents that is displayed by typing in the URL. I just want to hide all the data if possible

You can't remove the query string and be able to extract the "id". The "id" needs to be send with the request otherwise <? echo ($_GET['id'])?> will always be blank because, well, no "id" exists.

If you add it into the URL, then people can still type whatever they want, it's not going to hide anything anymore than the query string. It'll just look a little better.

Something like:

<td align="left"><a href="/review/'. $row['review'] . '/' . $row['movie_title']  .'/"> Read Review </a>

That makes the URL look like /review/idname/movietitle/

Then in your htaccess file:

Options -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewrteRule ^review/([^/]+)/([^/]+)/$ /review.php?id=$1&title=$2 [L,QSA]

Since the path changes, you may need to update your content so relative links resolve correctly (for things like images, styles, scripts, etc). You can do this by making all your links absolute or by adding this to your page headers:

<base href="/" />

Upvotes: 0

Martijn
Martijn

Reputation: 16123

It's called nice urls

# if it does not exist as a directory 
RewriteCond %{REQUEST_FILENAME} !-d 
# and if it does not exist as a file 
RewriteCond %{REQUEST_FILENAME} !-f 
# then add .php to get the actual filename 
RewriteRule ^(.*)/? index.php?q=$1 [L]

Whatever your url is, it will always end up in $_GET['q']. There you can do whatevery you want.

Upvotes: 1

Related Questions