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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.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_重写除root之外的所有内容_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Apache mod_重写除root之外的所有内容

Apache mod_重写除root之外的所有内容,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,嗨,我正在尝试编写一个mod_重写规则来重定向除根文件夹之外的所有内容。 例如,www.example.com应该加载index.html文件 对于其他所有内容,例如www.example.com/tag,/tag应该传递给子目录中的脚本 现在我有 RewriteCond %{REQUEST_URI} !^/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (.*) app/w

嗨,我正在尝试编写一个mod_重写规则来重定向除根文件夹之外的所有内容。 例如,www.example.com应该加载index.html文件 对于其他所有内容,例如www.example.com/tag,/tag应该传递给子目录中的脚本

现在我有

RewriteCond %{REQUEST_URI} !^/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) app/webroot/$1 [L]
这样可以很好地加载index.html,但是/tag不会传递给webroot。我得到一个404错误


谢谢

这种情况就是问题所在:

RewriteCond %{REQUEST_URI} !^/
你说的任何以“/”开头的内容都不会被重写,所有内容都以“/”开头。最后需要使用
$

RewriteCond %{REQUEST_URI} !^/$
不过,我不确定您是否需要该规则,因为如果index.html存在,其他两条规则将自动处理该问题。只需使用这些重写物理上不存在的任何内容:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ app/webroot/$1 [L,QSA]

你可以在你的应用程序中处理404错误,因为你无论如何都要处理子目录。

如果你将重写规则更改为重写规则(.*)http://yourdomain.com/app/webroot/$1[L,R]你重定向到的URL是什么?太好了!非常感谢你!我绞尽脑汁想弄明白这件事已经4个小时了。