2

我有这样的网址 http://www.shreyinnovations.com/edudemo/app-detail/?app-detail=A-Level%20Revision 我需要像下面这样替换 http://www.shreyinnovations.com/edudemo/ app/A-Level%20Revision

我将 .htaccess 文件更改为如下所示

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /edudemo/
RewriteRule ^app/([0-9]+)$ app-detail?app-detail=$1 [QSA]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /edudemo/index.php [L]

</IfModule>

# END WordPress

我还使用 wordpress 功能来更改 appche 规则以像这样重写地址

add_action( 'init', 'app_detail_rewrite_rules' );

add_action( 'generate_rewrite_rules', 'app_detail_rewrite_rules' );
function app_detail_rewrite_rules(){
   add_rewrite_rule('^app/([0-9]+)','app-detail?app-detail=$matches[1]','top');
}

但我仍然无法获得我想要的网址。如果有人对此有解决方案,请告诉我。

提前致谢。

4

1 回答 1

2

尝试在 WP 规则集之前添加此代码:

RewriteEngine On
RewriteCond %{REQUEST_URI}  ^/edudemo/app-detail [NC]
RewriteCond %{QUERY_STRING}  app-detail=([^&/]+) [NC]
RewriteRule .*               /edudemo/app/%1?    [R=301,L]              

# BEGIN WordPress

对于内部映射,从 [R=301,L] 中删除 R=301

于 2013-05-13T15:39:15.907 回答