【问题标题】:Generate page url jquery生成页面url jquery
【发布时间】:2018-12-10 22:29:28
【问题描述】:

我想从索引页面重定向到传递 id 的其他页面。 在 html 我有这个代码 我正在使用 jquery,我有这个代码。

$("<a class='theme-btn default-btn' href='#'>Read more </a></button>").appendTo($target).click(function() {
                    document.location.href='post.html?id=' + $id;
                });

重定向后的url是>http://example.com/post?id=14 我想变成这样>http://example.com/post/this-is-the-post-title 我该怎么做?

【问题讨论】:

  • 你能在jsfiddle.net上做一个样本吗?
  • 在 html 中我有

标签: mod-rewrite url-rewriting url-routing url-parameters


【解决方案1】:

我明白你在做什么。 您必须在服务器端使用重写 URL。

根据您的服务器设置,这将位于您的 web.config(用于 IIS)或 htaccess (Apache) 中。

下面是 IIS 重写规则的示例,在您的问题上下文中。

<rule name="Category Rule">
    <match url="post/([0-9]+)-([0-9]+)*.aspx" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
    <action type="Rewrite" url="post.aspx?id={R:1}" appendQueryString="true" />
</rule>

如果网址是; /post.aspx?id=14 这将返回 URL /post/14

为了使其正常工作,您的页面需要某种逻辑来确定显示哪些内容,具体取决于页面的 ID。例如,要抓取页面内容的数据库的哪一行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-13
    • 1970-01-01
    • 1970-01-01
    • 2015-05-08
    • 1970-01-01
    • 2019-08-02
    • 2021-05-07
    • 1970-01-01
    相关资源
    最近更新 更多