【发布时间】:2011-11-10 23:51:22
【问题描述】:
在我的 PHP 网页中,我想重定向如下:
header("Location: page2.php?id=$tid");
page2.php 需要查询字符串,但我不希望查询字符串显示在访问者的浏览器中。我想我可以使用 mod_rewrite 消除查询字符串,如下所示:
RewriteEngine On
RewriteRule ^page2\.php page2\.php?
这只是删除了 page2.php 的查询字符串(使其行为方式不理想),并且仍然在浏览器的 url 显示区域中显示查询字符串。
我发现了有关删除查询字符串的其他参考,例如 mod_rewrite: remove query string from URL? ,但是当我将重定向添加到 [R=permanent] 之类的规则时,我的浏览器显示的 url 来自
localhost/admin/page2.php?id=123
通过一个显示得很好的网页来
http://localhost/C:/xampp/htdocs/admin/page2.php
没有加载网页,而是显示以下内容:
Access forbidden!
You don't have permission to access the requested object.
It is either read-protected or not readable by the server.
If you think this is a server error, please contact the webmaster.
Error 403
localhost
9/5/2011 9:57:19 PM
Apache/2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4 mod_perl/2.0.4 Perl/v5.10.1
如何重定向到需要查询字符串的页面,但对访问者隐藏该查询字符串,以便他们的浏览器不会向他们显示?
【问题讨论】:
-
.htaccess 和 mod_rewrite 在 localhost 中通常不能正常工作
-
您是否有将 tid 传递给 page2.php 的替代方法?其次,不能使用 URL 重写来修改浏览器中显示的 URL。它用于内部将漂亮的 URL 翻译成丑陋的 URL。
标签: php apache url mod-rewrite query-string