douyong2531 2014-04-12 02:14
浏览 295
已采纳

.htaccess只允许访问并重定向到root index.php只有一个目录

I'm getting some troubles with htaccess in my new php project . I couldn't find any solutions so I ask here , hope someone will help me out.

1 . What I need :

On root , urls pointing to existing files and folders are not accessible , except /Public/ and all its folders and files ( only /Public/ is allowed to access ) . Urls pointing to files and folders which are not existings will be redirected to root index.php. /Public/ is redirected to root index.php too , folders and files inside it are not ( direct access ).

2 . What I have tried and are not working :

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /
 RewriteRule ^index\.php$ - [L]
 RewriteCond %{REQUEST_URI} !^/Public
 RewriteCond %{REQUEST_FILENAME} !^index\.php$
 RewriteCond %{REQUEST_FILENAME} -f
 RewriteCond %{REQUEST_FILENAME} -d
 RewriteRule . - [F,L,NC]
 RewriteBase /Public/
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /index.php [L,QSA]
</IfModule>
------------------------------------
<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /
 RewriteRule ^index\.php$ - [L]
 RewriteCond %{REQUEST_URI} !^/Public
 RewriteRule . - [F,L,NC]
 RewriteBase /Public/
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /index.php [L,QSA]
</IfModule>
------------------------------------
<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /
 RewriteRule ^index\.php$ - [L]
 RewriteCond %{REQUEST_FILENAME} -f
 RewriteCond %{REQUEST_FILENAME} -d
 RewriteRule . - [F,L,NC]
 RewriteBase /Public/
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /index.php [L,QSA]
</IfModule>

Thank you in advance :)

  • 写回答

1条回答 默认 最新

  • drvxclagw656708070 2014-04-12 14:10
    关注

    Try this code in root .htaccess:

    RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule !^public /index.php [L,NC]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效