2017-07-03 165 views
0

如何在.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

回答

0

這裏是例子:

<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>