字preSS自定义查询字符串和放大器; pretty的网址 - 如何? [英] Wordpress custom Querystrings & Pretty URL's - How?

查看:233
本文介绍了字preSS自定义查询字符串和放大器; pretty的网址 - 如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的新网站字preSS一个完美的(到目前为止)设置。在pretty的网址是否按预期工作。

I have a perfectly good (so far) setup of wordpress of for a new website. The pretty urls are working as expected.

我有1动态页面加载内容根据查询字符串:

I have 1 dynamic page that loads content depending on the querystring:

/dynamic/?loc=england&code=uk 

我想提出这个网址pretty的很好,但每一次我修改不进行任何更改。htaccess的。尝试一切,一派一切 - 最后的手段。如果我能得到如下的工作,那么我会很高兴。

I wish to make this URL "pretty" as well but every-time I modify the .htaccess no changes are made. Tried everything and googled everything else - last resort. If I could get the following to work then I would be happy.

我需要的URL的样子。

I need to make the URL look like.

/dynamic/location/england/code/uk/

添加这对任何的.htaccess打破了整个网站。

Adding this to any .htaccess breaks the whole website.

RewriteRule /dynamic/(.*)/(.*)/(.*)/(.*)/$ /dynamic?$1=$2&$3=$4

我在想什么。

What am i missing.

在此先感谢

N

推荐答案

不要重写规则添加到您的的.htaccess 文件。字preSS管理的文件给你,所以尝试时,您可以使用内置的功能。

Don't add the rewrite rule to your .htaccess file. WordPress manages that file for you, so try to use built-in features whenever you can.

字preSS实际上有一种高级重写引擎船舶标准 - 这是可插拔就像平台的其余部分。

WordPress actually has a somewhat advanced rewrite engine that ships standard - and it's pluggable just like the rest of the platform.

这一招,不过,正与它。您需要注册您的正则表达式等等话语preSS知道什么类型的字符串匹配(即动态/位置/(.*)/$ C $Ç/(.*) => /动态$ LOC = $ 1安培; code = $ 2 )。然后,你需要设置的页面和文字上的后端处理提交。

The trick, though, is working with it. You'll need to register your RegEx so WordPress knows what kinds of strings to match (i.e dynamic/location/(.*)/code/(.*) => /dynamic?$loc=$1&code=$2). Then you'll need to set up the page and script on the back end to handle the submission.

有关类似的例子,看看我收到解析自定义URL使用自定义职位的答案类型上的<一个href="http://word$p$pss.stackexchange.com/questions/1635/fixing-pagination-with-custom-taxonomy-archive/1640#1640">Word$p$pss答案的。扩展这一点,你需要设置code类似于以下(注意:未经测试!):

For a similar example, look at the answer I received to parsing custom URLs with a custom post type over on WordPress Answers. Extending this, you'll need to set up code similar to the following (note: untested!!!):

<?php
add_action('init', 'add_my_rewrite');

function add_my_rewrite() {
    global $wp_rewrite;
    $wp_rewrite->add_rule('location/([^/]+)/code/([^/]+)','index.php?loc=$matches[1]&code=$matches[2]','top');
    $wp_rewrite->flush_rules(false);  // This should really be done in a plugin activation
}

本的应该的补充重写结构,以你的的.htaccess 文件自动。

This should add the rewrite structure to your .htaccess file automatically.

这篇关于字preSS自定义查询字符串和放大器; pretty的网址 - 如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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