2014-03-28 56 views
0

我想以下结构:的Apache的.htaccess在共享服务器上的请求映射设置

|--- public_html 
    |--- dist 
    | |--- index.html 
    | |--- style.css 
    | |--- script.js 
    | |--- blog 
    | | |--- index.html 
    |--- index.php 
|--- .htaccess 

并为Apache先在/dist/,看是否有相匹配的,那么如果不使用/index.php。我怎样才能让apache通过.htaccess来做到这一点?

但我不希望它只是重定向,但是如果他们在Web根,以服务/dist/文件,因此:

example.com/blog 

供应本身,而是使用文件从example.com/dist/blog/index.html

我已经通过文档了解了很多,但是我感到困惑的是看似无数的重定向和在Apache中映射的方式。我会用哪个模块来做到这一点?

回答

0

把这个代码在你DOCUMENT_ROOT/.htaccess文件:

RewriteEngine On 

# if path available in /dist/ then use it 
RewriteCond %{DOCUMENT_ROOT}/dist/$1 -f [OR] 
RewriteCond %{DOCUMENT_ROOT}/dist/$1 -d 
RewriteRule ^(.+?)/?$ /dist/$1 [L] 

# otherwise forward to /index.php 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
相关问题