htaccess 上是否还有其他条件?

Har*_*ris 5 .htaccess

我的网站的“services”文件夹中有一个 .htaccess 文件,必须提供以下两个网址

htaccess 的内容

#------------------------
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteRule ^(.*)$ index.php?n=$1 [L,QSA] 
</IfModule>
$-------------------------

1. http://www.mysite.com/services/seo-work
2. http://www.mysite.com/services/online-editor
Run Code Online (Sandbox Code Playgroud)

使用 htaccess 重写的第一个 URL 像http://www.mysite.com/services/index.php?s=seo-work 这样工作正常。但是当我在同一文件夹“services”上上传其他文件 online-editor.php 时,它不起作用

那么第一个 url 应该如何使用 index.php?s=seo-work 显示页面,如果在目录中找不到页面“online-editor.php”,否则 online-editor.php 应该显示。我在下面以编程方式表示我的问题

if(IsFoundPageInDirectory(online-editor.php))
{
   GoToUrl(http://www.mysite.com/services/online-editor.php)
}
else
{
   GoToUrl(http://www.mysite.com/services/index.php?s=seo-work)
}
Run Code Online (Sandbox Code Playgroud)

请帮我解决这个问题 提前感谢您的回复

Nol*_*nig 6

Apache 配置中并没有真正的if/else条件ifModule,但是您可以在两种情况下使用测试 : !module& module,如下所示:

<IfModule !module>
  # default directives
</IfModule>

<IfModule module>
  # decorator directives
</IfModule>
Run Code Online (Sandbox Code Playgroud)


Eim*_*tas 0

检查默认的 WordPress .htaccess 文件。我认为您缺少对现有文件和目录的检查。就像是

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . index.php [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)