.htaccess - 重定向未按预期工作

.htaccess - Redirect not working as expected

我无法在我的网站上运行它:

# BEGIN pushState Routing
Options +FollowSymLinks
RewriteEngine On

RewriteCond %{SERVER_PORT} 80 

RewriteRule ^/tournament/(0-9)+$ /#tournament/ [R=301,NE,L]
# END pushState Routing

当我执行 ...example.com/tournament/11 时,我得到一个 404。它应该重定向到 example.com/#tournament/11 以便 Backbone.js 启用 pushState 并删除 hashtag 本身。

试试这个代码:

# BEGIN pushState Routing
Options +FollowSymLinks
RewriteEngine On

RewriteCond %{SERVER_PORT} =80 
RewriteRule ^/?(tournament/\d+)/?$ /# [R=301,NE,L,NC]
# END pushState Routing

前导斜杠在 .htaccess 中不匹配,因此最好将其设为可选以使其与 .htaccess 和 Apache 配置兼容。