【问题标题】:Ηtaccess fail to point index.php on subdirectoryΗtaccess 无法将 index.php 指向子目录
【发布时间】:2019-02-06 14:58:46
【问题描述】:

我正在尝试设置一个 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。

有什么想法吗?

【问题讨论】:

    标签: php .htaccess https no-www


    【解决方案1】:

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

    domain.com/en 不是目录/文件,因此 RewriteRule ^(.*)$ $1.php 为真并请求 /en.php

    【讨论】:

    • 你会建议其他关于 htaccess 的策略吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-28
    • 2011-08-05
    • 2013-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多