【问题标题】:.htaccess catching all invalid URLs.htaccess 捕获所有无效的 URL
【发布时间】:2013-09-09 02:17:40
【问题描述】:

我对此很陌生,但根据我的逻辑,这应该可行。

我想要做的是在结束前捕获所有不匹配任何规则的url,并将它们重定向到error.php。如果我尝试访问 localhost/create 或 localhost/create/ 它仍然会将我重定向到 error.php。我错过了什么吗?

RewriteEngine On

RewriteRule    ^create/?$    create.php    [NC,L]
RewriteRule ^ error.php [NC,L]

【问题讨论】:

    标签: .htaccess mod-rewrite


    【解决方案1】:

    这对我有用:

    Options +FollowSymLinks -MultiViews
    
    RewriteEngine On
    RewriteBase /
    
    RewriteRule ^create/?$ create.php [NC,L]
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ error.php [NC,L]
    

    您的规则的问题是它不检查文件或文件夹是否存在,所以基本上一旦找到create.php,它就会继续到error.php,因为它没有被要求验证文件是否存在。

    【讨论】:

      猜你喜欢
      • 2011-06-11
      • 2013-12-21
      • 2015-12-09
      • 1970-01-01
      • 2013-07-12
      • 1970-01-01
      • 2021-01-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多