【问题标题】:Set text to website from url从 url 将文本设置为网站
【发布时间】:2014-03-29 21:03:06
【问题描述】:

我正在尝试这样做:

例如,我有网站:

http://web.com

当我进入 http://web.com/text

网站将保持不变,但 <h1></h1> 将更改为 <h1>text</h1>

当我进入 http://web.com/title

网站将保持不变,但 <h1></h1> 将更改为 <h1>title</h1> 等。

【问题讨论】:

  • 它没有看到你尝试任何东西 - 到目前为止你只是想出了一个模糊的想法。
  • 您可以执行查询字符串之类的操作,或者从响应中获取 url 并从那里分解。你尝试了什么是一个更大的问题。
  • 尝试使用 Kelin,它是一个很棒的 PHP 路由器,可以让你做这样的事情,而且超级简单。

标签: url hyperlink get


【解决方案1】:

一种方法来做到这一点。 在你的 .htaccess

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/file.html$
RewriteRule .* /file.html [L,R=302]

在文件.html中

<h1 id="header">text</h1>
<script type="text/javascript">
if (window.location.pathname != "/") {
document.getElementById("header").innerHTML =  window.location.pathname;
}
</script>

【讨论】:

  • 显然,如果您不使用 .htaccess 或它被禁用,您将不得不以其他方式将所有请求指向 file.html。
猜你喜欢
  • 1970-01-01
  • 2023-03-08
  • 2014-06-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多