【问题标题】:Removing PHP extension and forcing HTTPS [duplicate]删除 PHP 扩展并强制使用 HTTPS [重复]
【发布时间】:2017-09-29 21:28:27
【问题描述】:

我想知道如何在我的网站及其所有目录中强制使用 HTTPS,并删除任何 .PHP 扩展名。我的 .htaccess 文件中有以下代码,但在某些目录中,即使它们确实存在,我也会得到 404。

RewriteEngine On
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.motherwellelim.org.uk/$1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

有什么建议吗?非常感谢!

【问题讨论】:

    标签: php .htaccess https url-rewriting


    【解决方案1】:

    对于从 http 到 https 的重定向站点,使用这个

     RewriteEngine On
     RewriteCond %{HTTPS} !=on
     RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
    

    您可以按照此代码轻松删除扩展。

    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]
    

    确保您已启用 rewrite_module。

    【讨论】:

      猜你喜欢
      • 2017-05-13
      • 1970-01-01
      • 2015-06-29
      • 2020-09-06
      • 1970-01-01
      • 2014-06-19
      • 2018-06-25
      • 2017-08-31
      • 1970-01-01
      相关资源
      最近更新 更多