htaccess无法在子目录上指向index.php

时间:2019-02-06 14:58:47

标签: php .htaccess https no-www

我正在尝试设置htaccess文件以删除.php.html扩展名,强制使用non-wwwhttps,但是在子目录中的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

它在httpsnon-www上完美运行,但是当我指向en子目录(domain.com/en)时,我在浏览器上收到以下消息:

  

在此服务器上找不到请求的URL /en.php。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

子目录的路径为domain.com/en/(以斜杠结尾)。

domain.com/en不是目录/文件,因此RewriteRule ^(。*)$ $ 1.php是真实的,需要/en.php