【问题标题】:How to use RewriteEngine in .htaccess file如何在 .htaccess 文件中使用 RewriteEngine
【发布时间】:2017-10-12 20:09:35
【问题描述】:

我当前的 .htaccess 文件包含此代码

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} .*jpg$|.*gif$|.*png$|.*mp3$ [NC]
RewriteRule (.*) /viewed.php?file=$1

我想更改它,如果扩展名为 not .php,它会将 URL 重写为 /viewed.php?file=$1($1 是文件路径),但我不知道如何要做到这一点。 (我在另一篇文章中找到了该代码并将我自己的扩展添加到列表中)

如果有人可以将我链接到重写条件如何工作的解释,那就太好了,因为我不明白如何制作它们。

【问题讨论】:

    标签: php apache .htaccess mod-rewrite


    【解决方案1】:

    全部重写,如果不是.php

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !^.*\.php$ [NC]
    RewriteRule (.*) /viewed.php?file=$1 [L]
    

    文档: http://httpd.apache.org/docs/current/mod/mod_rewrite.html

    学习正则表达式: https://regexone.com/

    【讨论】:

      猜你喜欢
      • 2020-10-27
      • 2014-08-25
      • 2023-03-04
      • 1970-01-01
      • 1970-01-01
      • 2017-03-20
      • 2017-09-08
      • 1970-01-01
      • 2014-11-15
      相关资源
      最近更新 更多