Change url with get parameters to url with path. Wordpress site

ⅰ亾dé卋堺 提交于 2021-02-08 11:25:24

问题


I have a wordpress site.

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

or

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

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

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

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...

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

Real link from the website: https://www.officeshop.co.il/product/%D7%A9%D7%95%D7%9C%D7%97%D7%9F-%D7%9E%D7%A0%D7%94%D7%9C%D7%99%D7%9D-%D7%99%D7%95%D7%A7%D7%A8%D7%AA%D7%99-%D7%93%D7%92%D7%9D-spider-glass-%D7%9B%D7%95%D7%9C%D7%9C-%D7%9E%D7%99%D7%A1%D7%AA%D7%95%D7%A8/?build=product-572

I want to change it to: https://www.officeshop.co.il/product/%D7%A9%D7%95%D7%9C%D7%97%D7%9F-%D7%9E%D7%A0%D7%94%D7%9C%D7%99%D7%9D-%D7%99%D7%95%D7%A7%D7%A8%D7%AA%D7%99-%D7%93%D7%92%D7%9D-spider-glass-%D7%9B%D7%95%D7%9C%D7%9C-%D7%9E%D7%99%D7%A1%D7%AA%D7%95%D7%A8/build/product-572


回答1:


You can simply change permalinks using the WordPress Dashboard.

Steps: Login to WordPress Dashboard -> Settings -> Permalink Settings.




回答2:


How to customize url in wordpress site

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

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.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' ));



来源:https://stackoverflow.com/questions/59478152/change-url-with-get-parameters-to-url-with-path-wordpress-site

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!