htaccess rewrite if redirected file exists

后端 未结 3 953
情书的邮戳
情书的邮戳 2020-12-16 03:50

The problem: Some html pages of php equivalents (apple.html, apple.php; orange.html, orange.php), but not all do (grapes.html).

The goal: If the php version exists,

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-16 04:39

    you should be able to achieve that by using two conditions:

    RewriteCond %{REQUEST_FILENAME} (.*)\.html$
    RewriteCond %1\.php -f
    RewriteRule ^(.*)\.html$ $1.php [R,L]
    

    The first condition checks if the filename ended with .html and the second uses the back reference %1 from the first condition to check if .php version exists.

    Hope it helps. :)

提交回复
热议问题