duangan6636 2016-03-19 08:39
浏览 108

Htaccess需要:http到https - 不存在的文件,文件夹,子域到404 - 只有第一个工作

I need to add rewrites in .htaccess as described in title, but only the first one works, here is how my .htaccess looks now:

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

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /404.php [R,L]

ErrorDocument 404 /404.php

Examples that does not work

These two NON EXISTING SUBDOMAINS examples just hang then show "Unable to connect", but I want them to show REAL 404 error page:

http://nonexisting.example.com
https://nonexisting.example.com

If we enter NON EXISTING FILES or FOLDERS, for example:

https://example.com/nonexistingfile.php
https://example.com/nonexistingfolder/

it shows my 404.php page allright BUT they turn up as a SOFT 404 and I want it to show the REAL 404 error page.

I have tried around 30 different variations of the second Rewrite section without any success. Some code returned a REAL 404 code but showed a messed up page not my 404.php page.

  • 写回答

1条回答 默认 最新

  • drpjdfj618393 2016-03-19 11:32
    关注

    You don't need a rewrite rule here which is just redirecting all non-existing files or directories to /404.php with R=302.

    Just try this code:

    # will send correct 404 status as well
    ErrorDocument 404 /404.php
    
    RewriteEngine On
    
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [R=302,NE,L]
    
    评论

报告相同问题?

悬赏问题

  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类