前往EDIT8怎么看我解决了这个
让我们说我有一个字preSS博客: www.animals.com
。我在我的主题目录一定的PHP文件: www.animals.com/wp-content/themes/mytheme/db.php
。另外,我有该页面的模板,所以我创造的字preSS管理面板的新页面显示 db.php中
: www.animals.com/database
。
Let's say I have a Wordpress blog: www.animals.com
. I have a certain PHP file in my theme directory: www.animals.com/wp-content/themes/mytheme/db.php
. Also, I have a custom template for that page, so I create a new page in the Wordpress administration panel to show db.php
: www.animals.com/database
.
所以,如果我想读一些关于狮子,我只是去: www.animals.com/database/?animal=lion
(因为那是我决定的方式写PHP,从$ _ GET ['动物']插入值到查询,使用PDO等)。
So if I want to read something about lions, I just go to: www.animals.com/database/?animal=lion
(because that's the way I decided to write the PHP, inserting the value from $_GET['animal'] into the query, using PDO etc.).
现在,我想访问 www.animals.com/database/?animal=lion
为 www.animals.com /狮
。
Now, I would like to access www.animals.com/database/?animal=lion
as www.animals.com/lion
.
我应该使用的.htaccess或Word preSS改写?我应该在哪里把我的.htaccess,在Word中preSS文件夹的根目录下(与WP-config.php文件和这些文件),或在我的主题目录?
Should I use .htaccess or Wordpress Rewrite? Where should I place my .htaccess, in the root of the Wordpress folder (with wp-config.php and those files) or in my theme directory?
从根的人有的RewriteBase /
之类的东西从Word preSS默认。我应该怎么写实现我想要什么?我应该把它之前或之后,现有的code?
The one from the root has RewriteBase /
and stuff from Wordpress by default. What should I write to achieve what I want? Should I put it before or after the existing code?
修改:这是我的的public_html 的.htaccess,这是我的真的想做的事:
我有一个网站: www.domain.com
,当你键入这个 http://www.domain.com/dios/?dios=agni
这表明你对神烈火的信息。我想键入 www.domain.com/dioses/agni
访问有关神烈火的信息。该PHP文件是在 www.domain.com/wp-content/themes/smitespain/dios.php
它不工作X_X
EDIT: this is my public_html .htaccess and this is what I really want to do:
I have a website: www.domain.com
and when you type this http://www.domain.com/dios/?dios=agni
it shows you the info about the god Agni. I would like to type www.domain.com/dioses/agni
to access the info about the god Agni. The PHP file is in www.domain.com/wp-content/themes/smitespain/dios.php
It's not working x_x
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^dioses/(w*)$ dios/?dios=$1 [NC,L]
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
EDIT2 :我使用多点(检查EDIT4),然后再次/数据库/ /奥斯/和/ dioses /是的不可以实际文件夹,那是因为我在Word preSS创建的页面的名称。问题是,现在它显示在标签标题中的神的名字:这意味着变量$ _GET ['奥斯']设为S,但它不加载该文件(dios.php)= /
EDIT2: i'm using multisite (check EDIT4), and again, /database/ /dios/ and /dioses/ are not actual folders I created, thats the name for the page I created in Wordpress. The thing is, now it shows the name of the god in the tab title :S that means the variable $_GET['dios'] is set, but it doesnt load the file (dios.php) =/
EDIT3 :我需要访问domain.com/dios/?dios=agni具体而言,因为那将让从字的PHP文件(dios.php)加载get_header()的网址preSS,所以我不能直接访问该文件
EDIT3: I need to access domain.com/dios/?dios=agni specifically, because thats the URL that will let the PHP file (dios.php) to load get_header() from wordpress, so i cant access the file directly
EDIT4 :我决定取消多站点的事情
EDIT4: I decided to remove the multisite thing
EDIT5 :这些都是字preSS的网页,我有:
domain.com/dioses /
为(www.domain.com/wp-content/themes/smitespain/dioses.php)
domain.com/dios/?dios=thor
为(www.domain.com/wp-content/themes/smitespain/dios.php)
EDIT5: these are the Wordpress pages I have:
domain.com/dioses/
for (www.domain.com/wp-content/themes/smitespain/dioses.php)
domain.com/dios/?dios=thor
for (www.domain.com/wp-content/themes/smitespain/dios.php)
EDIT6 :我在读什么东西的话preSS codex..and意识到,如果我想去到 domain.com/dioses
我可以去 domain.com/index.php?pagename=dioses
或 domain.com/?pagename访问= dioses
所以,我说这在的RewriteBase /
和下一条规则之间:重写规则的例子/测试页面名称= dioses 和 domain.com/example/test
重定向我 domain.com/dioses
,但它也改变了URL地址栏中:(
问题是,如果我试试这个:重写规则的例子/测试页面名称=奥斯和放大器;奥斯=雷神
将送我的页面奥斯'没有'奥斯=?雷神
EDIT6: i was reading something in the wordpress codex..and realized that, if i wanna go to domain.com/dioses
i can access it by going to domain.com/index.php?pagename=dioses
or domain.com/?pagename=dioses
So, i added this between the Rewritebase /
and the next rule: RewriteRule example/test ?pagename=dioses
and domain.com/example/test
redirects me to domain.com/dioses
but it also changes the url in the address bar :(
The thing is, if i try this: RewriteRule example/test ?pagename=dios&dios=thor
it will send me to the page 'dios' without the '?dios=thor'
EDIT7 :我开始使用文字preSS重写,我已将此添加到我的主题的functions.php中:
EDIT7: i started using wordpress rewrite, i added this to my theme's functions.php:
function my_rewrite_rules() {
add_rewrite_rule(
'blah',
'index.php?pagename=dios&dios=agni',
'top'
);
}
add_action( 'init', 'my_rewrite_rules' );
和again..it加载页面奥斯,没有?奥斯=烈火
and again..it loads the page dios, without the ?dios=agni
EDIT8 :最后,我设法使它工作=)
我需要知道的第一件事就是,新的?奥斯= XXXX
将不再提供给 $ _ GET ['奥斯']
相反,你需要调用 $ wp_query-&GT; query_vars ['奥斯']
所以我说这对我的主题的functions.php的
EDIT8: and finally, I managed to make it work =)
the first thing i needed to know is, the new ?dios=XXXX
will be no longer available to $_GET['dios']
instead, you need to call $wp_query->query_vars['dios']
so i added this to my theme's functions.php
function add_query_vars($new_var) {
$new_var[] = "dios";
return $new_var;
}
add_filter('query_vars', 'add_query_vars');
function add_rewrite_rules($rules) {
$new_rules = array('([^/]+)' => 'index.php?pagename=dios&dios=$matches[1]');
$rules = $new_rules + $rules;
return $rules;
}
add_filter('rewrite_rules_array', 'add_rewrite_rules');
我要确保 $ wp_query-&GT; query_vars ['奥斯']
实际上是设置
然后我刚才添加的普通规则
i make sure $wp_query->query_vars['dios']
is actually set
then i just add the regular rule
推荐答案
还有另一种方式来解决它,而不触及字preSS。
There is another way to solve it, without touching WordPress.
添加为.htaccess
Add to .htaccess
RewriteRule ^lion /indexw.php?pagename=db&dios=$1 [L,E=URI:/detail/]
创建文件indexw.php:
Create file indexw.php:
<?php $_SERVER["REQUEST_URI"] = $_SERVER["REDIRECT_URI"]; include("index.php");
它是如何工作的? mod_rewrite的设置REDIRECT_URI在E = URI规定:值参数。 indexw.php只是覆盖REQUEST_URI用正确的值(感谢拉维Thapliyal查找有关此的见解)
How it works? mod_rewrite sets REDIRECT_URI as specified in E=URI:value argument. indexw.php just overwrites REQUEST_URI with correct value (Thanks to Ravi Thapliyal for an insight on this)
相关推荐
最新文章