您将需要某种方式使用 JavaScript 对字段进行编码,并在字符串到达 PHP 时对其进行解码。选择一个前进和后退的编解码器应该相当容易,即使只使用 base64 也应该这样做。(JavaScript 没有对 base64 编码的内置支持,但周围有很多这样的例子。)如果你有一些其他的编码和解码字段的方法,那也很好。
在服务器端,您将不得不使用Apache mod_rewrite 规则进行一些重写。基本上,您会在 httpd.conf 部分或本地 .htaccess 文件中需要类似的内容:
# use mod_rewrite to enable passing encoded user name as a "Clean URL"
RewriteEngine On
# Define the rewrite base -- / says use what is immediately after the hostname part
RewriteBase /
# Send bare requests to index.php
RewriteRule ^$ index.php [L]
# Don't rewrite requests for files, directories, or symlinks
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
# Send requests to index.php, appending the portion following the RewriteBase
RewriteRule ^(.*)$ index.php?n=$1 [QSA,L]
The last will rewrite your original url: "http://www.example.com/johnsmithencoded" to "http://www.example.com/index.php?n=johnsmithencoded", from there, you can get the query parameter via $_GET['n'] and decode it as needed.