【发布时间】:2014-05-26 08:38:19
【问题描述】:
我在我的新 php 项目中遇到了一些 htaccess 问题。我找不到任何解决方案,所以我在这里问,希望有人能帮助我。
1 .我需要什么:
在根目录下,无法访问指向现有文件和文件夹的 URL,除了 /Public/ 及其所有文件夹和文件(仅允许 /Public/ 访问)。指向不存在的文件和文件夹的 URL 将被重定向到 root index.php。 /Public/ 也被重定向到 root index.php ,其中的文件夹和文件不是(直接访问)。
2 。我尝试过但不起作用的方法:
<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>
提前谢谢你:)
【问题讨论】:
-
你在linux上?检查 apache 用户是否可以访问公用文件夹以外的文件
-
我在 windows 上做我的项目。但是完成后我会在一些linux环境下测试它
标签: php apache .htaccess mod-rewrite redirect