我想使用框架创建基本的 URL 重写。
我无权访问 .htaccess
来执行 mod_rewrite
。
有没有办法使用 PHP、jQuery、JavaScript 等来检测哪个 URL 被点击,然后在新框架中打开 URL?
例如:用户点击 /index.php?12345
它将在框架窗口 /pages/12345/index.html
中打开,并且如果他们点击 /index.php?54321
URL 将在框架窗口中打开 /pages/54321/index.html
最佳答案
我想我不太明白你的意思。通常 url 重写的工作方式如下:
用户点击http://example.com/content/example
重写为http://example.com/index.php?cat=content&page=example
您可以通过将链接设置为 http://example.com/index.php/content/example 来伪造这种效果。网络服务器仍然会请求页面index.php,然后您可以在其中读取index.php之后(但在查询字符串之前)的部分
$_SERVER['PATH_INFO']
然后解析它以获得您需要的内容。
$_SERVER['PATH_INFO'] 上的 PHP.net
Contains any client-provided pathname information trailing the actual script filename but preceding the query string, if available. For instance, if the current script was accessed via the URL http://www.example.com/php/path_info.php/some/stuff?foo=bar, then $_SERVER['PATH_INFO'] would contain /some/stuff.
关于php - 检测链接何时被单击,在新框架中打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1516662/