的RewriteCond跳过规则,如果存在文件或目录跳过、规则、存在、文件

2023-09-02 00:41:37 作者:遇见之夏

我想调整我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]

目录/项目/ NTI存在,有一个index.php文件。当地址mywebsite.com/folder/project/nti输入,它改变mywebsite.com/folder/project/nti/?view=project&project=nti~~V。我在测试服务器的示例站点是一个子文件夹在应用这一点,但实施时,它会在根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] 和你的code是这样的:

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]
 
精彩推荐
图片推荐