Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.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
Regex 重写条件不起作用_Regex_Apache_.htaccess_Mod Rewrite_Redirect - Fatal编程技术网

Regex 重写条件不起作用

Regex 重写条件不起作用,regex,apache,.htaccess,mod-rewrite,redirect,Regex,Apache,.htaccess,Mod Rewrite,Redirect,在我的php-项目中,我有以下文件夹结构 / [root] |-- ... [some other folders] |-- util/ // containing js,css files; should be accessible for anyone. |-- client/ |--data/ // contains files which can be uploaded by users |-- privat

在我的
php
-项目中,我有以下文件夹结构

/ [root]
|-- ... [some other folders]
|-- util/            // containing js,css files; should be accessible for anyone.
|-- client/          
    |--data/         // contains files which can be uploaded by users
       |-- private/  // should only be accessible for logged in users
       |-- public/   // should be accessible for anyone.
|-- ... [some other folders]
|-- index.php
我希望实现以下行为:

  • 如果有人直接访问util/中的任何内容,如果它不是目录,他应该只获取他请求的内容
  • 如果有人想访问
    client/
    中的任何文件,应该将其重定向到index.php。 例如,有人输入url
    www.test.com/client/data/private/test.jpg
    服务器应以
    index.php?request1=client/data/private/test.jpg
    的形式获取请求
  • 其他所有内容都应重写为
    index.php?request2=$1
  • 我无法按照预期获得点2函数

    我使用以下.htaccess文件来处理此问题:

    RewriteEngine On
    
    # allow access to all files within util/  WORKS!!
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)(util)($|/) - [L]
    
    # here i have problems.. how can i achieve, that access to folder client/ is rewritten to index.php?request1=$1
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} ^client
    RewriteRule ^(.*)$ index.php?request1=$1 [QSA,L]
    
    # rewriting everything else   WORKS!!
    RewriteRule ^(.+)$ index.php?request2=$1 [QSA,L]
    
    我做错了什么

    请尝试以下代码:

    RewriteEngine On
    
    # allow access to all files within util/  WORKS!!
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^util($|/) - [L]
    
    # here i have problems.. how can i achieve, that access to folder client/ is rewritten to index.php?request1=$1
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^client(/.*|)$ index.php?request1=$1 [QSA,L]
    
    # rewriting everything else WORKS!!
    RewriteRule ^((?!index\.php).+)$ index.php?request2=$1 [QSA,L]
    

    如果未请求特定文件,则
    /client/dir1/dir2
    会发生什么情况?是应该重写为index.php,还是应该不修改目录访问?这应该被重写规则3捕获,或者抛出以下http错误401404之一。但是我更喜欢规则3Ah等等--
    请求URI
    在匹配为
    ^/client
    时可能应该有一个前导的
    //code>,因为这是头的结构。这与
    RewriteRule
    在目录上下文中所期望的匹配方式相反。试一试,这可能就是你所需要的。其他一切对我来说都很好。那也不起作用。。。但我想,感谢您重新编写日志并开始调试。RewriteRule:无法编译正则表达式“^((?!index\\.php.+)$”