HTAccess需要重写

时间:2010-08-22 16:27:45

标签: .htaccess mod-rewrite

我需要在我的域名上重写任何以** / club / *** anyPage *开头的网址到/ page / club / anyPage

为此,我相信我可以使用以下命令:

RewriteRule ^club/([^/]*)$ /page/club/$1 [NC]

另外,如果物理页面不存在,我希望它有条件地重写,如下所示:

  

/ club / $ 1 /page/club/club.php?title=$1

所以在这种情况下,如果用户进入mysite.com/club/New_Club,他们实际上应该正在查看/page/club/club.php?title=New_Club

1 个答案:

答案 0 :(得分:1)

您的原始规则似乎可以正常工作,但要合并第二个要求,这样的事情应该可以胜任......

# do first rule if not file/directory
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteRule ^club/([^/]*)$ /page/club/club.php?title=$1 [NC]
# do second rule if not file/directory
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteRule ^club/([^/]*)$ /page/club/$1 [NC]

或取决于其他规则......

# prevent requests for real files / directories from rewritting at all
RewriteCond %{REQUEST_URI} -f
RewriteCond %{REQUEST_URI} -d
RewriteRule .* - [L]

RewriteRule ^club/([^/]*)$ /page/club/$1 [NC]
RewriteRule ^club/([^/]*)$ /page/club/club.php?title=$1 [NC]