rewritcondition隐藏查询字符串


RewriteCondition hide the query string

我试图隐藏URL中的查询字符串。

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

我已经尝试了一些重写条件,但没有工作,但这是我第一次尝试这个过程。

任何帮助都将是非常感激的。

数据是这样显示的

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

发送方式:

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

这叫做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]

无论你的url是什么,它总是以$_GET['q']结尾。在那里你可以做任何你想做的事。

通过输入URL来防止人们编辑显示的内容。如果可能的话,我只是想隐藏所有的数据

您不能删除查询字符串而能够提取"id"。"id"需要与请求一起发送,否则<? echo ($_GET['id'])?>将始终为空白,因为不存在"id"。

如果你把它添加到URL中,那么人们仍然可以输入他们想要的任何东西,它不会隐藏除了查询字符串以外的任何东西。这样看起来会好一点。

类似:

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

使URL看起来像/review/idname/movietitle/

然后在你的htaccess文件中:

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

由于路径改变,您可能需要更新您的内容,以便正确解析相对链接(例如图像,样式,脚本等)。你可以将所有链接设置为绝对链接,或者在页面标题中添加以下内容:

<base href="/" />