[英]WordPress rewrite URL returning 404 Not Found
I'm trying to redirect this url: 我正在尝试重定向此网址:
myurl.com/track/124 myurl.com/track/124
to this one: 对此:
myurl.com/wp-content/themes/themefolder/track.php?id=124 myurl.com/wp-content/themes/themefolder/track.php?id=124
The parameter value 124 can be anything. 参数值124可以是任何值。 I have modified the .htaccess file on the root of the server so now it has this:
我已经修改了服务器根目录上的.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
However when I go to myurl.com/track/124 I 404 Not Found returned. 但是,当我访问myurl.com/track/124时,返回了404 Not Found。 Can anyone spot the problem and help me fix this?
谁能发现问题并帮助我解决此问题?
Thanks 谢谢
I think you need to change 我认为你需要改变
RewriteRule ^track/?$ wp-content/themes/themefolder/track.php?id=$1 [QSA,R,L]
to 至
RewriteRule ^track/(\d+) wp-content/themes/themefolder/track.php?id=$1 [QSA,R,L]
Try using Wordpress' built in function add_rewrite_rule 尝试使用Wordpress的内置函数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');
}
You will then need to visit your permalinks page in settings (Dashboard->Settings->Permalinks->Save Changes) in order for the added rule to take effect. 然后,您将需要在设置(仪表板->设置->永久链接->保存更改)中访问永久链接页面,以使添加的规则生效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.