Apache多重重写规则
问题描述:
如何在.htaccess文件中重写多个规则?Apache多重重写规则
以下是我的.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/download(.*)$
RewriteRule ^(.*)/download/(.*)$ download/$2 [L]
RewriteCond %{REQUEST_URI} ^/file(.*)$
RewriteRule ^(.*)/file/(.*)$ file/$2 [L]
RewriteRule ^(.*)$ main/$1 [L]
</IfModule>
如果请求的URL是http://localhost/ {}下载/foo.php然后运行下载/ foo.php
如果请求的URL是http://localhost/ {file} /foo/bar.php然后运行文件/ foo/bar.php
如果不是在规则中则运行main/index.php
答
这里是例子:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/download/.*$ [NC]
RewriteRule ^/download/(.*) download/$1 [L]
RewriteCond %{REQUEST_URI} ^/file/.*$ [NC]
RewriteRule ^/file/(.*) file/$1 [L]
RewriteCond %{REQUEST_URI} !^(/download/(.*)|/file/(.*))$ [NC]
RewriteRule ^(.*)$ main/$1 [L]
</IfModule>