Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache mod_rewrite在传递到php之前检查公用文件夹_Apache_Mod Rewrite - Fatal编程技术网

Apache mod_rewrite在传递到php之前检查公用文件夹

Apache mod_rewrite在传递到php之前检查公用文件夹,apache,mod-rewrite,Apache,Mod Rewrite,我试图实现的(使用mod_rewrite)是根据请求检查公用文件夹中是否存在文件/目录,如果存在,则提供服务,如果不存在,则将请求路由到index.php文件。如果URL中没有提供扩展名,则默认为.html 以下是我的文件夹结构: /.htaccess /index.php /public /test.html /test.xml /a_folder /index.html /test.html 例如,这里有一些请求和响应: examp

我试图实现的(使用mod_rewrite)是根据请求检查公用文件夹中是否存在文件/目录,如果存在,则提供服务,如果不存在,则将请求路由到index.php文件。如果URL中没有提供扩展名,则默认为.html

以下是我的文件夹结构:

/.htaccess
/index.php
/public
    /test.html
    /test.xml
    /a_folder
        /index.html
        /test.html
例如,这里有一些请求和响应:

  • example.com/test.xml>/public/test.xml
  • example.com/a_folder/>/public/a_folder/index.html
  • example.com/a_folder/test>/public/a_folder/test.html
  • example.com/not\u in\u public>>/index.php
任何关于这方面的提示都将是惊人的,提前谢谢。

类似的内容:(大量抄袭了我的WordPress.htaccess文件)


重新启动发动机
重写基/
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)^(\.\w+)$1.html[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]
$1.html
行超出了我的想象,可能需要一些调整。请注意,这是一个哑检查,检查请求的URL是否以点结尾,后跟一个或多个单词字符


<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^(|index\.php)$ - [L]
    RewriteRule ^public/(.*)$ - [L]
    RewriteRule ^(.*)$ public/$1
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php [R]
</IfModule>
重新启动发动机 重写基/ 重写规则^(| index\.php)$-[L] 重写规则^public/(.*)$-[L] 重写规则^(.*)$public/$1 重写cond%{REQUEST_FILENAME}-F 重写cond%{REQUEST_FILENAME}-D 重写规则。index.php[R]
这应该能奏效


基本上,如果它是
/
/index.php
它不会做任何事情,如果它是
/public/whateveryouwant
它不会做任何事情,如果它是其他内容,它将重写为
/public/whateveryouwant
,并检查它是文件还是目录。如果不是,它将重定向到
index.php

,这要感谢@jxpx777和@N1xx1,经过一点杂耍,它才工作了

Options -Indexes

RewriteEngine On
RewriteBase /
RewriteRule ^public/(.*)$ - [L]

# Check public cache
RewriteRule ^(.*)$ public/$1
RewriteRule (.*)/$ $1/index

# Add .html if not extension provided
RewriteCond %{REQUEST_URI} !\..*$
RewriteRule ^(.*)$ $1.html

# Push through stack in not in cache
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

+谢谢你,这不完全是我想要的,但它帮助我找到了答案。+1谢谢你,这不完全是我想要的,但它帮助我找到了答案。
Options -Indexes

RewriteEngine On
RewriteBase /
RewriteRule ^public/(.*)$ - [L]

# Check public cache
RewriteRule ^(.*)$ public/$1
RewriteRule (.*)/$ $1/index

# Add .html if not extension provided
RewriteCond %{REQUEST_URI} !\..*$
RewriteRule ^(.*)$ $1.html

# Push through stack in not in cache
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]