gpt4 book ai didi

regex - .htaccess 重写问题

转载 作者:行者123 更新时间:2023-12-02 06:36:18 26 4
gpt4 key购买 nike

要么我真的需要回到课 table ,要么发生了一些奇怪的事情。

以下不起作用,因为真实的物理文件和目录无法解析:

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

# The following rule must not affect real physical files, but does
RewriteRule ^(img/.*)$ http://old.site.com/$1 [L,R=301]

RewriteRule .* index.php [L]
</IfModule>

但是这段代码可以正常工作并解析真实的文件和文件夹:

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(img/.*)$ http://old.site.com/$1 [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule .* index.php [L]
</IfModule>

我真的需要在每个 RewriteRule 之前有一个新的 RewriteCond 吗?

最佳答案

RewriteCond 仅适用于下一个 RewriteRule。所以是的,在您的情况下,您需要在每个 RewriteRule 之前有一个 RewriteCond。

但好消息是它是可以避免的。

如果你想避免写这些多个 RewriteCond 你可以这样做代码:

## If the request is for a valid directory
RewriteCond %{REQUEST_FILENAME} -d [OR]
## If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} -f [OR]
## If the request is for a valid link
RewriteCond %{REQUEST_FILENAME} -l
## don't do anything
RewriteRule ^ - [L]

RewriteRule ^(img/.*)$ http://old.site.com/$1 [L,R=301]

RewriteRule .* index.php [L]

关于regex - .htaccess 重写问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17806680/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com