使用get参数将url更改为使用path的url.WordPress网站 [英] Change url with get parameters to url with path. Wordpress site

查看:65
本文介绍了使用get参数将url更改为使用path的url.WordPress网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个wordpress网站.

I have a wordpress site.

它有一个产品页面,其中显示了根据给定的GET参数对产品进行的一些修改.

It has a product page that shows some modifications of a product depending on GET parameter given.

https://www.officeshop.co.il/product/product-name-1/?build=product-572

https://www.officeshop.co.il/product/product-name-1/?build=product-573

我要使网址看起来像这样:

I want to make the url look like this:

https://www.officeshop.co.il/product/product-name-1/build/product-572

https://www.officeshop.co.il/product/product-name-1/product-572

我尝试使用.htaccess文件管理重定向,但未成功.

I have tried managing redirects with .htaccess file but did not succeed.

每次" https://www.officeshop.co.il/product/product-name-1/build/product-572 "指向404页.

Every time the "https://www.officeshop.co.il/product/product-name-1/build/product-572" leads to 404 page.

.htaccess文件中的重写规则看起来完全无效.可能会被wordpress覆盖吗?或者我没有使用正确的规则...

Looks like the rewrite rules in the .htaccess file have no effect at all. May be it is getting overwritten with wordpress? Or I did not use the correct rules...

我将.htaccess文件放在网站的根文件夹中.

I put the .htaccess file in the root folder of the website.

该网站的真实链接:我想将其更改为:推荐答案

如何在wordpress网站中自定义网址

How to customize url in wordpress site

例如: http://example.com/your-page-slug/?cat = categoryname& name =产品名称看起来像这样: http://example.com/your-page-slug/类别名称/产品名称/

Ex: http://example.com/your-page-slug/?cat=categoryname&name=productname To Look like this: http://example.com/your-page-slug/categoryname/productname/

1.创建页面模板2.创建一个页面(您的页面名称),然后分配给创建的模板(第一点)3.将下面的代码和过去的内容复制到function.php文件中

1.Create a page template 2.Create a page (your page name) then assign to created template (First point) 3.Copy the below the code and past in function.php file

add_action( 'init', 'url_getparam_init' ); 
function url_getparam_init(){
// rewrite rule tells wordpress to expect the       given url pattern
add_rewrite_rule( '^your-page-slug/(.*)/?', 'index.php?    page_id=your_page_id&getparam=$matches[1]', 'top' ); 
}
add_filter('query_vars', 'view_getparam_from_url');
function view_getparam_from_url($vars) {
$vars[] = 'getparam';
return $vars;
}

4.然后保存永久链接(登录到WordPress仪表板->设置->永久链接设置)5.然后从您创建的页面模板print_r(get_query_var('getparam'));

4.Then save the permalinks (Login to WordPress Dashboard -> Settings -> Permalink Settings) 5.Then get param from your created page template print_r(get_query_var( 'getparam' ));

这篇关于使用get参数将url更改为使用path的url.WordPress网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆