通过字preSS或改写的.htaccess URL重写(URL rewriting via Wordpress Rewrite or .htaccess)

   IT问题网   2019-04-01 00:00:00

问 题

前往edit8怎么看我解决了这个


让我们说我有一个字press博客: www.animals.com 。我在我的主题目录一定的php文件: www.animals.com/wp-content/themes/mytheme/db.php 。另外,我有该页面的模板,所以我创造的字press管理面板的新页面显示 db.php中: www.animals.com/database 。

所以,如果我想读一些关于狮子,我只是去: www.animals.com/database/animal=lion (因为那是我决定的方式写php,从$ _ get ['动物']插入值到查询,使用pdo等)。

现在,我想访问 www.animals.com/database/animal=lion 为 www.animals.com /狮。

我应该使用的.htaccess或word press改写?我应该在哪里把我的.htaccess,在word中press文件夹的根目录下(与wp-config.php文件和这些文件),或在我的主题目录?

从根的人有的rewritebase / 之类的东西从word press默认。我应该怎么写实现我想要什么?我应该把它之前或之后,现有的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

 #begin字press
 ifmodule mod_rewrite.c
rewriteengine叙述上
的rewritebase /
重写规则^ dioses /(\ w *)$奥斯/?奥斯= $ 1 [nc,l]
重写规则^指数\ .php $-[l]
的rewritecond%{} request_filename!-f
的rewritecond%{} request_filename!-d
重写规则。的index.php [l]
 / ifmodule

#结束字press
 

edit2 :我使用多点(检查edit4),然后再次/数据库/ /奥斯/和/ dioses /是的不可以实际文件夹,那是因为我在word press创建的页面的名称。问题是,现在它显示在标签标题中的神的名字:这意味着变量$ _get ['奥斯']设为s,但它不加载该文件(dios.php)= /

edit3 :我需要访问domain.com/dios/dios=agni具体而言,因为那将让从字的php文件(dios.php)加载get_header()的网址press,所以我不能直接访问该文件

edit4 :我决定取消多站点的事情

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)

edit6 :我在读什么东西的话press codex..and意识到,如果我想去到 domain.com/dioses 我可以去 domain.com/index.phppagename=dioses 或 domain.com/pagename访问= dioses
所以,我说这在的rewritebase / 和下一条规则之间:<?code>重写规则的例子/测试页面名称= dioses 和 domain.com/example/test 重定向我 domain.com/dioses ,但它也改变了url地址栏中:(
问题是,如果我试试这个:重写规则的例子/测试页面名称=奥斯和放大器;奥斯=雷神将送我的页面"奥斯'没有'奥斯=?雷神"

edit7 :我开始使用文字press重写,我已将此添加到我的主题的functions.php中:

 函数my_rewrite_rules(){
add_rewrite_rule(
'嗒嗒',
'index.php的页面名称=奥斯和放大器;奥斯=烈火',
'最佳'
);
}
add_action('init','my_rewrite_rules');
 

和again..it加载页面奥斯,没有?奥斯=烈火

edit8 :最后,我设法使它工作=)
我需要知道的第一件事就是,新的?奥斯= xxxx 将不再提供给 $ _ get ['奥斯'] 相反,你需要调用 $ wp_query- query_vars ['奥斯'] 所以我说这对我的主题的functions.php的

 函数add_query_vars($ new_var){
$ new_var [] ="奥斯";
返回$ new_var;
}
的add_filter('query_vars','add_query_vars');

功能add_rewrite_rules($规则){
$ new_rules =阵列("([^ /] +)='index.php的页面名称=奥斯和放大器;奥斯= $匹配[1]");
$规则= $ new_rules + $规则;
返回$规则;
}
的add_filter('rewrite_rules_array','add_rewrite_rules');
 

我要确保 $ wp_query- query_vars ['奥斯'] 实际上是设置
然后我刚才添加的普通规则

解决方案

还有另一种方式来解决它,而不触及字press。

添加为.htaccess

 重写规则^狮/indexw.phppagename=dbamp;dios=$1 [l,e = uri:/详细/]
 

创建文件indexw.php:

  php $ _ server ["request_uri"] = $ _ server ["redirect_uri"];包括:("的index.php");
 

它是如何工作的? mod_rewrite的设置redirect_uri在e = uri规定:值参数。 indexw.php只是覆盖request_uri用正确的值(感谢拉维thapliyal查找有关此的见解)

标签:通过或者改写重写



分享:

  • 微信
  • QQ好友
  • QQ空间
  • 新浪微博


热门推荐

如何阻止多个mod_rewrite的通行证(或无限循环)在htaccess的背景下(How to block multiple mod_rewrite passes (or infinite loops) in a .htaccess context)

problem i'm working on a website running on a ...

Zend框架和Word preSS集成(Zend Framework and Wordpress Integration)

problem we have an existing zend framework site hosted at ...

如何删除&QUOT;网络/ app_dev.php&QUOT;从Symfony2的网址?(How to remove &quot;web/app_dev.php&quot; from Symfony2 URLs)

problem i just created my first symfony2 project. but the ...

通过301重定向404误差的.htaccess的搜索引擎优化等(Redirecting 404 error with .htaccess via 301 for SEO etc)

problem i couldn't find a straight answer to my question ...

而不进行任何验证的IP地址(Allow IP address without authentication)

problem i have set up a site that is currently work in pr ...

HTTP的当量=英寸×UA兼容&QUOT;内容=IE =边缘,镀铬= 1......在.htaccess把这个?(http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge,chrome=1&quot; ... Putting this in .htaccess)

problem i downloaded html5 boilerplate and it wouldnt val ...

如何使用mod_headers中和mod_expires缓存(how to use mod_headers and mod_expires to cache)

problem i want to cache images and other files on my site ...

如何从一个子目录中删除的.htaccess密码保护(How to remove .htaccess password protection from a subdirectory)

problem i have password protected my entire website using ...

请.git目录网站无法访问(Make .git directory web inaccessible)

problem i have a website that i use github (closed source ...

重写URL以htaccess的(rewrite url with htaccess)

problem first of all i am a beginner so please answer in ...

重写QUOT&; pretty的网址&QUOT;?(Rewrite to &quot;pretty URL&quot;)

problem this is an example of what i am trying to achieve ...

需要mod_rewrite的URL信息(mod_rewrite URL info required)

problem i am new to this mod_rewrite. i have been success ...

的.htaccess,迫使斜线和www(.htaccess, forcing a slash and www)

problem can someone please help me to force my website to ...

简单的301重定向在.htaccess与查询字符串不以重定向指令工作(Simple 301 redirect in .htaccess with query string does not work with Redirect directive)

problem i am trying to redirect a single url in a .htacce ...

如何将文本转换使用的.htaccess为小写的网址(How to convert text to lowercase URLs using .htaccess)

problem i want to set up 301 redirects in my .htaccess fi ...

&QUOT;双向&QUOT;改写(&quot;Two Way&quot; Rewrite)

problem so, i'm trying to accomplish this: we have a url ...

与字preSS除非使用URL重写不工作[R](Url rewriting not working with wordpress unless using [R])

problem i have a wordpress installation on my website on ...

通过htaccess的重定向所有的HTTP和HTTPS非www网址https://www.xyz.com(Redirect all http AND https non-www URLS to https://www.xyz.com via htaccess)

problem for reasons much too long and complex to get into ...

重定向的* .htm为* .PHP(Redirect *.htm to *.php)

problem i am trying find out how to redirect all traffic ...

HTTPS重定向到非www和http到www(Redirect https to non-www and http to www)

problem i searched and found hundreds of related cases, b ...