.htaccess multi RewriteRule和RewriteCond帮助我将它们组合在一起

时间:2014-07-09 04:36:36

标签: regex .htaccess mod-rewrite

我需要以下.htaccess的帮助,如果可能的话,我需要将它们组合在一起

如果前端没有http://wwwhttp://,则会重定向到域名前面的www的domainname.com.au:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^domainname.com.au$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domainname.com.au$
RewriteRule ^(.*)$ "http\:\/\/www\.domainname.com.au\/$1" [R=301, OR]

这个应该在斜杠/之后得到在域名末尾传递的变量,我应该看到" / contact"但是php MVC看到了这个" /index.php?url = contact"

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

deny from 111.93.163.217

谢谢!

1 个答案:

答案 0 :(得分:0)

两个规则不能合并,因为它们完全不同,但它们可以缩短:

# Force www
RewriteCOnd %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# Rewrite parameter
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [B,NE,QSA,L]