dpblwmh5218
2012-09-25 01:31
浏览 137
已采纳

.htaccess - 重定向到真实目录500错误

mydomain.com/forum/ is a real directory.

When I do add these 2 lines to my .htaccess:

RewriteRule ^forum/([a-zA-Z0-9_-]+)/new-thread /forum/new-thread.php?comm=$1 [L]
RewriteRule ^forum/([a-zA-Z0-9_-]+) /forum/community.php?comm=$1 [L]

mydomain.com/forum/ AKA mydomain.com/forum/index.php throws a 500 error, as well as all rules that are supposed to be changed by these lines. What am I doing wrong?

图片转代码服务由CSDN问答提供 功能建议

mydomain.com/forum/是一个真实目录。

当我将这两行添加到我的.htaccess时:

  RewriteRule ^ forum /([a-zA-Z0-9 _-] +)/ new  -thread /forum/new-thread.php?comm=$1 [L] 
RewriteRule ^ forum /([a-zA-Z0-9 _-] +)/ forum /community.php?comm = $ 1 [L] 
    
 
 

mydomain.com/forum / AKA mydomain.com/forum/index.php 会引发500错误, 以及应该由这些行改变的所有规则。 我做错了什么?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dotxo86440 2012-09-25 02:46
    已采纳

    You need to add boundaries to your regular expressions. For example, the regex ^forum/([a-zA-Z0-9_-]+) matches both /forum/new-thread and /forum/community so your rules are looping. You can either add the $ end of string match to your regex or add conditions to stop the rewrite:

    RewriteRule ^forum/([a-zA-Z0-9_-]+)/new-thread$ /forum/new-thread.php?comm=$1 [L]
    RewriteRule ^forum/([a-zA-Z0-9_-]+)$ /forum/community.php?comm=$1 [L]
    

    or

    RewriteCond %{ENV:REDIRECT_STATUS} 200
    RewriteRule ^ - [L]
    
    RewriteRule ^forum/([a-zA-Z0-9_-]+)/new-thread /forum/new-thread.php?comm=$1 [L]
    RewriteRule ^forum/([a-zA-Z0-9_-]+) /forum/community.php?comm=$1 [L]
    

    or

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^forum/([a-zA-Z0-9_-]+)/new-thread /forum/new-thread.php?comm=$1 [L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^forum/([a-zA-Z0-9_-]+) /forum/community.php?comm=$1 [L]
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题