简体   繁体   English

wordpress .htaccess重写网址

[英]wordpress .htaccess rewrite url

I am developing quiz section for my wordpress site. 我正在为我的wordpress网站开发测验部分。 I have W3 total cache installed on my site. 我的网站上安装了W3总缓存。 I want to put quiz on 我想测验

http://www.example.com/quiz/seo-friendly-title/id http://www.example.com/quiz/seo-friendly-title/id

and rewrite htaccess to redirect the url to 并重写htaccess将网址重定向到

http://www.example.com/quiz?title=seo-friendly-title&quiz-id=id http://www.example.com/quiz?title=seo-friendly-title&quiz-id=id

The quiz section is developed as wordpress template and a blank page is made using this template. 测验部分已开发为wordpress模板,并使用此模板制作了空白页。

This is .htaccess I wrote. 这是我写的.htaccess。

<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^quiz/([\\w\\d\\-]+)/(\\d]+)$ quiz?title=$1&quiz-id=$2 [L] RewriteRule ^index\\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>

Any form of help would be appreciated! 任何形式的帮助将不胜感激!

Did you go to settings and permalinks? 您是否已进入设置和固定链接? if yes and its not what you want have a look here 如果是,不是您想要的,请在这里查看

how to hide a page from being seen in wordpress backend and frontend 如何隐藏页面以防止在wordpress后端和前端中看到

add_action('init', 'a_add_rewrite_rule');
function a_add_rewrite_rule(){
// add_rewrite_rule(REGEX url, location, priority (i.e. top is before other rewrite rules)
// I created a custom post type for this plugin called market -- replace post_type with whatever you want 
//basically tell wordress to add a query var if sidebar is added to url.
add_rewrite_rule('^sidebar?','index.php?is_sidebar_page=1&post_type=market','top');
}

// register a query var
add_action('query_vars','market_set_query_var');
function market_set_query_var($vars) {
array_push($vars, 'is_sidebar_page');
return $vars;
}

// associate a template with your quer_var 
add_filter('template_include', 'market_include_template', 1000, 1);
function market_include_template($template){
if(get_query_var('is_sidebar_page')){
   $new_template = (theme or plugin path).'/pages/yourpage.php'; // change this path to your file 
if(file_exists($new_template))
    $template = $new_template;
} 
return $template;
}

You can try this: 您可以尝试以下方法:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteRule ^quiz/seo-friendly-title/(.*)$ quiz?title=seo-friendly-title&quiz-id=$1 [R,L]

    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM