mod rewrite directory if file/folder not found

前端 未结 1 1826
情书的邮戳
情书的邮戳 2021-01-01 01:05

I have a folder named \"folder1\" in my root directory

www.domain.com/ www.domain.com/folder1

I need to redirect all the requests to www.dom

相关标签:
1条回答
  • 2021-01-01 01:37
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_URI} !^/folder1/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) folder1/$1 [L,R]
    
    • The first rewrite-cond ensures you do not loop (in case the file does not exist inside folder1 either
    • The second one checks that target is not a file
    • The third - that it is not a folder either
    • And, finally, rewrite the url. L flag means this is the last rule applied (even if there are rules after it), R means redirect. You can also add QSA flag if you want any query-string parameters passed to the original be sent to the new url
    0 讨论(0)
提交回复
热议问题