简体   繁体   English

用自定义参数重写WordPress URL

[英]Rewrite WordPress URL with custom paramater

I am working on a site that has an image slide show. 我正在一个有图像幻灯片放映的网站上工作。 When changing slides I change the URL using history and append a parameter too. 更改幻灯片时,我使用历史记录更改URL并附加参数。 What I need to do is make the URL tidier. 我需要做的是使URL更整洁。

The URL can be saved for later and I pull the data from the current structure fine. 可以保存URL以供日后使用,我可以从当前结构中提取数据。

Example URL: 示例网址:

http://domain.com/projects/single-landscape/?layout_id=1

The projects is a post type and the single-landscape is a post in that post type. 项目是一种帖子类型,单一格局是该帖子类型的帖子。

The ?layout_id is simply something I add myself with JS so nothing to do with WordPress itself. ?layout_id只是我用JS添加自己的东西,所以与WordPress本身无关。

All i'm looking to do is be able enter: 我要做的就是输入:

http://domain.com/projects/single-landscape/1
http://domain.com/projects/single-landscape/2
http://domain.com/projects/single-landscape/3

And carry on the same as I am now pulling out that number as the layout id. 并继续我现在拉出那个数字作为布局ID。 The projects part is fixed as its the only post type im using in this case and but the 'single-project' can change. 在这种情况下,项目部分被固定为唯一的post类型im,但“单项目”可以改变。

Looking through the docs doesn't seem to help for me, just need a simple push in the right direction with an example and i'm sure ill then understand. 浏览文档对我来说似乎没什么帮助,只需要用一个例子简单地推进正确的方向,我肯定会生病,然后才能理解。

This will do it, reference here : 这样做, 参考这里

RewriteEngine on

RewriteRule ^(projects/[^/]+/)(\d+)$ $1?layout_id=$2

Put it in your root .htaccess file. 把它放在你的root .htaccess文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM