如果文件或目录存在,则 RewriteCond 跳过规则 [英] RewriteCond to skip rule if file or directory exists

查看:23
本文介绍了如果文件或目录存在,则 RewriteCond 跳过规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果文件或目录存在,我正在尝试调整我的 htacess 文件以跳过重写规则,但是当文件存在时,它将 URL 更改为不同的内容.我不知道为什么会这样.这是我的 htaccess 文件:

I am trying to adjust my htacess file to skip the rewrite rule if the file or directory exists, but when the file exists, it changes the URL to something different. I don't know why this is happening. Here is my htaccess file:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^project/([^/\.]+)/?$ index.php?view=project&project=$1 [L]
RewriteRule ^for/content/ag index.php?view=opening&section=ag [L]
RewriteRule ^for/content/bus index.php?view=opening&section=bus [L]
RewriteRule ^for/content/fcs index.php?view=opening&section=fcs [L]
RewriteRule ^for/content/market index.php?view=opening&section=market [L]
RewriteRule ^for/content/trade index.php?view=opening&section=trade [L]
RewriteRule ^for/content/teched index.php?view=opening&section=teched [L]
RewriteRule ^for/content/([^/\.]+)/?$ index.php?view=content_area&section=$1 [L]

目录/project/nti存在,有一个index.php文件.当输入地址 mywebsite.com/folder/project/nti 时,它会更改为 mywebsite.com/folder/project/nti/?view=project&project=nti.我在测试服务器上应用它,其中示例站点位于子文件夹中,但实施后,它将位于根 Web 服务器文件夹中.

The directory /project/nti exists, with an index.php file. When the address mywebsite.com/folder/project/nti is entered, it changes to mywebsite.com/folder/project/nti/?view=project&project=nti. I am applying this on a test server where the sample site is in a subfolder, but when implemented, it will be in the root web server folder.

感谢您的帮助!

推荐答案

移除额外的 [OR] 并让你的代码像这样:

Remove extra [OR] and have your code like this:

# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
# If the request is not for a valid link
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^project/([^/.]+)/?$ index.php?view=project&project=$1 [L,NC,QSA]

这篇关于如果文件或目录存在,则 RewriteCond 跳过规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆