如何将 mod_rewrite 规则应用到所有子目录?

如何将 mod_rewrite 规则应用到所有子目录?

最近我给我的一个网站添加了一个域名:原域名:ss.rsportugal.org 新域名:supremeskillers.net

我使用这个 .htaccess 文件强制重定向 ~/public_html/ss/.htaccess

RewriteEngine On
RewriteCond %{HTTP_HOST} !^supremeskillers\.net$ [NC]
RewriteRule ^/?(.*) http://supremeskillers.net/$1 [L,R=301]

但是重定向不适用于论坛子目录,我想知道问题是否出在“漂亮的网址”.htaccess:~/public_html/ss/forum/.htaccess

RewriteEngine on
RewriteBase /forum

# Rules for: actions
RewriteRule ^(activate|admin|announce|attachapprove|buddy|calendar|clock|collapse)/?$ ./index.php?pretty;action=$1 [L,QSA]
RewriteRule ^(coppa|credits|deletemsg|display|dlattach|editpoll|editpoll2|emailuser)/?$ ./index.php?pretty;action=$1 [L,QSA]
RewriteRule ^(findmember|groups|help|helpadmin|im|jseditor|jsmodify|jsoption)/?$ ./index.php?pretty;action=$1 [L,QSA]
RewriteRule ^(lock|lockvoting|login|login2|logout|markasread|mergetopics|mlist)/?$ ./index.php?pretty;action=$1 [L,QSA]
RewriteRule ^(moderate|modifycat|modifykarma|movetopic|movetopic2|notify|notifyboard|openidreturn)/?$ ./index.php?pretty;action=$1 [L,QSA]
RewriteRule ^(pm|post|post2|printpage|profile|quotefast|quickmod|quickmod2)/?$ ./index.php?pretty;action=$1 [L,QSA]
RewriteRule ^(recent|register|register2|reminder|removepoll|removetopic2|reporttm|requestmembers)/?$ ./index.php?pretty;action=$1 [L,QSA]
RewriteRule ^(restoretopic|search|search2|sendtopic|smstats|suggest|spellcheck|splittopics)/?$ ./index.php?pretty;action=$1 [L,QSA]
RewriteRule ^(stats|sticky|theme|trackip|about:mozilla|about:unknown|unread|unreadreplies)/?$ ./index.php?pretty;action=$1 [L,QSA]
RewriteRule ^(verificationcode|viewprofile|vote|viewquery|viewsmfile|who|\.xml|xmlhttp)/?$ ./index.php?pretty;action=$1 [L,QSA]

# Rules for: boards
RewriteRule ^([-_!~*'()$a-zA-Z0-9]+)/?$ ./index.php?pretty;board=$1.0 [L,QSA]
RewriteRule ^([-_!~*'()$a-zA-Z0-9]+)/([0-9]*)/?$ ./index.php?pretty;board=$1.$2 [L,QSA]

# Rules for: topics
RewriteRule ^([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/?$ ./index.php?pretty;board=$1;topic=$2.0 [L,QSA]
RewriteRule ^([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/([0-9]*|msg[0-9]*|new)/?$ ./index.php?pretty;board=$1;topic=$2.$3 [L,QSA]

问题是 ss.rsportugal.org/ 已正确重定向,而 ss.rsportugal.org/forum 未重定向。我能做些什么来解决这个问题?

答案1

我无法从配置中找出到底出了什么问题(没有简单的方法可以判断规则我正在申请),但也许我可以提供一些故障排除建议。

  • 简化。更少的移动部件使调试更容易。特别是,看看何时不宜重写。例如,我建议像这样替换您的域名转发重写:

    重定向 /http://supremeskillers.net/

  • 尝试在主程序中设置它.htaccess而不使用RewriteBase指令。这个总是让人困惑。

  • Redirect您也可以使用该指令来简化“操作”块。

  • 尝试一次测试一次重写。

相关内容