Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.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
htaccess regex-FilesMatch使用url/中最后一个目录的字符串,在最后一个斜杠之后_Regex_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

htaccess regex-FilesMatch使用url/中最后一个目录的字符串,在最后一个斜杠之后

htaccess regex-FilesMatch使用url/中最后一个目录的字符串,在最后一个斜杠之后,regex,apache,.htaccess,mod-rewrite,Regex,Apache,.htaccess,Mod Rewrite,我这里有一个代码,它重写URL,拒绝具有扩展名的文件名,并允许特定的文件 RewriteEngine On # XAMPP /Brian # Trailing Slash RewriteCond %{REQUEST_URI} !/Brian/$ RewriteCond %{REQUEST_URI} !\.[^/]*$ RewriteRule !/$ %{REQUEST_URI}/ [L,R=301] RewriteCond %{REQUEST_FILENAME} !-d # XAMPP /Br

我这里有一个代码,它重写URL,拒绝具有扩展名的文件名,并允许特定的文件

RewriteEngine On
# XAMPP /Brian
# Trailing Slash
RewriteCond %{REQUEST_URI} !/Brian/$
RewriteCond %{REQUEST_URI} !\.[^/]*$
RewriteRule !/$ %{REQUEST_URI}/ [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-d
# XAMPP /Brian
#Exclude from redirect
RewriteCond %{REQUEST_URI} !^/Brian/index.php$
RewriteCond %{REQUEST_URI} !^/Brian/pass.txt$
RewriteCond %{REQUEST_URI} !^/Brian/dist/.*\.(css|js)$

RewriteRule .* index.php

<FilesMatch "[^/]*(?!.*\/)\..*$">
    Order Deny,Allow
    Deny from all
    Allow from 127.0.0.1
</FilesMatch>

<FilesMatch "\.(php|css|js|txt)$">
    Order Allow,Deny
    Allow from all
</FilesMatch>
我的问题是这个

http://localhost:8080/Brian/pass.txts/pass2.txt -> http://localhost:8080/Brian/pass.txts/pass2.txt # NOT CORRECT, no slash added, error 403
我注意到filematch只读取第一个斜杠前面的字符串,即
pass.txts
,而不是
pass2.txt

如何让它读取最后一个斜杠后的最后一个字符串?我需要帮助。谢谢

更新:

RewriteEngine On
# XAMPP /Brian
# Trailing Slash
RewriteCond %{REQUEST_URI} !/Brian/$
RewriteCond %{REQUEST_URI} !\.[^/]*$
RewriteRule !/$ %{REQUEST_URI}/ [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-d
# XAMPP /Brian
#Exclude from redirect
RewriteCond %{REQUEST_URI} !^/Brian/index.php$
RewriteCond %{REQUEST_URI} !^/Brian/pass.txt$
RewriteCond %{REQUEST_URI} !^/Brian/dist/.*\.(css|js)$

RewriteRule .* index.php

RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1$
RewriteRule ^[^/.]+\.[^/.]+$ - [F]

RewriteRule !\.(php|css|js|txt)$ - [NC,F]
然后:

这将匹配
REQUEST\u URI
中的
.txt
,而不是从
REQUEST\u FILENAME
获取它
F
用于将
禁止的
403
返回给客户端


您的完整.htaccess:

DirectoryIndex inddex.php
RewriteEngine On
# XAMPP /Brian
# Trailing Slash
RewriteCond %{REQUEST_URI} !/Brian/$
RewriteCond %{REQUEST_URI} !\.[^/]*$
RewriteRule !/$ %{REQUEST_URI}/ [L,R=301]

RewriteCond %{REMOTE_ADDR} !^(127\.0\.0\.1|::1)$
RewriteRule ^[^/.]+\.[^/.]+$ - [F]

RewriteRule !\.(php|css|js|txt)$ - [NC,F]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/Brian/(index\.php|pass\.txt|/dist/.*\.(css|js))$ [NC]
RewriteRule . index.php [L]

由于
,它给出了错误403。我应该如何处理它?是的,它确实有效,但对其他文件的限制将被删除。您尝试的完整URL是什么?它只允许
http://localhost:8080/Brian/pass.txt
否,
http://localhost:8080/Brian/pass.txt由于此
RewriteCond%{REQUEST\u URI},因此不允许重写
^/Brian/pass.txt$
<FilesMatch "[^/]*(?!.*\/)\..*$">
    Order Deny,Allow
    Deny from all
    Allow from 127.0.0.1
</FilesMatch>
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1$
RewriteRule ^[^/.]+\.[^/.]+$ - [F]
<FilesMatch "\.(php|css|js|txt)$">
    Order Allow,Deny
    Allow from all
</FilesMatch>
RewriteRule !\.(php|css|js|txt)$ - [NC,F]
DirectoryIndex inddex.php
RewriteEngine On
# XAMPP /Brian
# Trailing Slash
RewriteCond %{REQUEST_URI} !/Brian/$
RewriteCond %{REQUEST_URI} !\.[^/]*$
RewriteRule !/$ %{REQUEST_URI}/ [L,R=301]

RewriteCond %{REMOTE_ADDR} !^(127\.0\.0\.1|::1)$
RewriteRule ^[^/.]+\.[^/.]+$ - [F]

RewriteRule !\.(php|css|js|txt)$ - [NC,F]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/Brian/(index\.php|pass\.txt|/dist/.*\.(css|js))$ [NC]
RewriteRule . index.php [L]