我有这样的网址 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');
}
但我仍然无法得到我想要的网址。如果有人有解决方案,请告诉我。
提前感谢。
答案 0 :(得分:1)
尝试在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