【问题标题】:Redirect from root to Specific URI with HTTPD.conf使用 HTTPD.conf 从根目录重定向到特定 URI
【发布时间】:2017-09-10 21:46:15
【问题描述】:

当维护文件到位时,第一条规则可以正常工作。如果不是 - 第二条规则不会重定向到特定的 URI。是否存在规则排序问题或?

 #########################################

   RewriteCond %{DOCUMENT_ROOT}/server_maintenance.html -f
   RewriteCond %{REQUEST_FILENAME} !/server_maintenance.html
   RewriteRule ^.*$ /server_maintenance.html [L]

  #########################################
  ## the %{HTTP_HOST} evaluates to the HTTP header with the name given in this case host.server.org, with NC being non case sensitive.
  ## it will rewrite the url at the server side to append the URI of lawson/portal
  ##########################################################################
   RewriteCond %{HTTP_HOST} ^host\.server\.org$ [NC]
   RewriteRule ^host\.server\.org$ "https\:\/\/host\.server\.org\/lawson\/portal" [L]

  #########################################

【问题讨论】:

    标签: apache httpd.conf aix


    【解决方案1】:

    你没有匹配 RewriteRule 中的主机名,即使你已经在之前定义的 RewriteCond 中匹配了主机名。

    那就这样吧:

    RewriteCond %{HTTP_HOST} ^host\.server\.org$ [NC]
    RewriteRule ^ https://host.server.org/lawson/portal [L]
    

    注意:RewriteRule 目标/目的地不是正则表达式,因此不需要转义每一件小事。

    注意2:单个 ^ 将匹配任何内容

    【讨论】:

    • 使用此方法 - 我收到以下问题:您无权访问此服务器上的 /。选项指令禁止的目录索引:/lsf10/webdocs/
    • 如果您没有设置索引或目录索引,您希望 apache 如何为目录提供服务?
    猜你喜欢
    • 2017-02-20
    • 1970-01-01
    • 2012-06-19
    • 2015-09-02
    • 2019-07-20
    • 2021-11-26
    • 2015-10-21
    • 1970-01-01
    • 2012-08-15
    相关资源
    最近更新 更多