[英]wordpress and custom htaccess rules
I am looking over my code for 3 hours and I don't get it. 我正在检查我的代码3个小时,但没有收到。 I hope that you can help me. 我希望你能帮助我。
I have a wordpress blog with Custom Post Types and Advanced Custom Fields installed. 我有一个wordpress博客,其中安装了“ 自定义帖子类型”和“ 高级自定义字段” 。 Its working pretty nice. 它的工作相当不错。 I use a basic filter function over the custom fields as described here: http://www.advancedcustomfields.com/resources/creating-wp-archive-custom-field-filter/ 我在自定义字段上使用了基本的过滤器功能,如下所述: http : //www.advancedcustomfields.com/resources/creating-wp-archive-custom-field-filter/
To filter the custom fields I use the get-parameters form the url. 为了过滤自定义字段,我使用URL的get-parameters。 So the url comes in the form like: 因此,URL的格式如下:
www.domain.tld/?post_type=movie&land=usa&typ=love&actor=kidman www.domain.tld /?post_type = movie&land = usa&typ = love&actor = kidman
Now I would like the have a pretty url in the form: 现在我想要一个漂亮的URL形式:
www.domain.tld/movie/usa/love/kidman www.domain.tld / movie / usa / love / kidman
And hier comes the issue, I cant get the .htaccess right :( 而更麻烦的是,我无法正确使用.htaccess :(
My Code is: 我的代码是:
AddHandler php56-cgi .php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^movie/(.*)/(.*)/(.*)$ /?post_type=movie&land=$1&typ=$2&actor=$3 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
It's not working. 没用 The result is a 404. I believe is's a "wordpress-thing" that I don't get. 结果是404。我相信这是我没有得到的“ wordpress-thing”。
If I change the code to: 如果我将代码更改为:
RewriteRule ^movie/(.*)/(.*)/(.*)$ http://www.domain.tld/?post_type=movie&land=$1&typ=$2&actor=$3 [L]
It works as a normal redirect. 它用作普通重定向。
If I change it to 如果我将其更改为
RewriteRule ^movie/(.*)/(.*)/(.*)$ file.php/?post_type=movie&land=$1&typ=$2&actor=$3 [L]
where file.php is a non wordpress file, it works as well (It shows the content of file.php) 其中file.php是非wordpress文件,它也可以正常工作(它显示了file.php的内容)
It seems that I'am not able to "call" a wordpress-specific file like index.php. 看来我无法“调用”诸如index.php之类的特定于wordpress的文件。
I hope you can help me, and thanks that you read through my non native english ;) 希望您能对我有所帮助,并感谢您通读我的非母语英语;)
Greetings from germany Dominik 来自德国多米尼克的问候
I solved my problem on my own :) 我自己解决了问题:)
As always, the solution is pretty simple if know where to look. 与往常一样,如果知道从哪里看,解决方案就非常简单。
I had a deep look into: http://codex.wordpress.org/Rewrite_API/add_rewrite_rule and http://codex.wordpress.org/Rewrite_API/add_rewrite_tag Finally the coin dropped. 我进行了深入研究: http : //codex.wordpress.org/Rewrite_API/add_rewrite_rule和http://codex.wordpress.org/Rewrite_API/add_rewrite_tag最终硬币掉了。
First I deleted every custom code I made in the .htaccess cause its not the location to solve my problem. 首先,我删除了我在.htaccess中创建的每个自定义代码,导致其无法解决我的问题。
I added the following to my functions.php 我在我的functions.php中添加了以下内容
function custom_rewrite_basic() {
add_rewrite_rule('^movie/(.*)/(.*)/(.*)?', 'index.php?post_type=movie&land=$matches[1]&typ=$matches[2]&actor=$matches[3]', 'top');
}
add_action('init', 'custom_rewrite_basic');
function custom_rewrite_tag() {
add_rewrite_tag('%land%', '([^&]+)');
add_rewrite_tag('%typ%', '([^&]+)');
add_rewrite_tag('%actor%', '([^&]+)');
}
add_action('init', 'custom_rewrite_tag', 10, 0);
After you edited your function.php don't forget to save the permalinks in your wordpress settings. 编辑function.php之后,不要忘记将永久链接保存在wordpress设置中。
Now I have access to the "query_vars" in the template : 现在,我可以访问模板中的“ query_vars”:
$wp_query->query_vars['land']
or the functions.php : 或functions.php :
$query->query_vars[ land ]
It works perfect :) 它完美的工作:)
Thank u anyway and have a nice weekend Dominik 无论如何,谢谢你,祝你周末愉快Dominik
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.