我试图重定向此网址:
myurl.com/track/124
到这一个:
myurl.com/wp-content/themes/themefolder/track.php?id=124
参数值 124 可以是任何内容。我已经修改了服务器根目录下的.htaccess文件,所以它现在有了这个:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^track/?$ wp-content/themes/themefolder/track.php?id=$1 [QSA,R,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
然而,当我去myurl.com/track/124时,我发现了404 Not Found。谁能发现问题并帮我解决这个问题?
由于
答案 0 :(得分:1)
我认为你需要改变
RewriteRule ^track/?$ wp-content/themes/themefolder/track.php?id=$1 [QSA,R,L]
到
RewriteRule ^track/(\d+) wp-content/themes/themefolder/track.php?id=$1 [QSA,R,L]
答案 1 :(得分:0)
尝试使用Wordpress&#39;内置函数add_rewrite_rule
add_filter('init','my_rewrite_rules');
function my_rewrite_rules(){
add_rewrite_rule('^track/([^/]*)/?','wp-content/themes/themefolder/track.php?id=$matches[1]','top');
}
然后,您需要在设置中访问固定链接页面(信息中心 - >设置 - &gt;固定链接 - >保存更改),以使添加的规则生效。