【发布时间】:2019-02-06 14:58:46
【问题描述】:
我正在尝试设置一个 htaccess 文件以删除 .php 和 .html 扩展名,强制 non-www 和 https 但它在子目录内的 index.php 上失败。
我在 htaccess 中有以下语法:
RewriteEngine on
# Redirect www and http to https - non-www
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
# Start php extension remove
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
# End php extension remove
# Start html extension remove
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
# End html extension remove
它在 https 和 non-www 上完美运行,但是当我指向 en 子目录 (domain.com/en) 时,我在浏览器上收到以下消息:
在此服务器上找不到请求的 URL /en.php。
有什么想法吗?
【问题讨论】:
标签: php .htaccess https no-www