Apache 在Windows中启用mod_rewrite以便.htaccess工作

Apache 在Windows中启用mod_rewrite以便.htaccess工作,apache,.htaccess,tomcat,Apache,.htaccess,Tomcat,我想在ApacheTomcat服务器上运行Angular 6应用程序。但每次我在深度链接URL中重新加载时,它都会显示状态404未找到页面。 因此,为此,我在index.html所在的根文件夹中包含了.htaccess文件。 但是,它仍然不起作用,因为可能未启用模块重写 为了启用mod_rewrite,我搜索了httpd.conf文件,我必须在其中进行更改。但是在我的“C:\Program Files\Apache软件基金会\Tomcat 9.0”目录中没有这样的文件 那么,如何启用mod_re

我想在ApacheTomcat服务器上运行Angular 6应用程序。但每次我在深度链接URL中重新加载时,它都会显示状态404未找到页面。 因此,为此,我在index.html所在的根文件夹中包含了.htaccess文件。 但是,它仍然不起作用,因为可能未启用模块重写

为了启用mod_rewrite,我搜索了httpd.conf文件,我必须在其中进行更改。但是在我的“C:\Program Files\Apache软件基金会\Tomcat 9.0”目录中没有这样的文件


那么,如何启用mod_rewrite使.htaccess工作并重新加载Angular应用程序而不出错呢?

Tomcat不使用httpd.conf,这是一个apache文件。各个webapp的位置保存在各自的web.xml文件中,但所有配置的位置都在../tomcat8/conf/server.xml和web.xml中

尝试WAMP或Apache2而不是Tomcat

您需要在每次点击时引导.htaccess文件加载
index.html

您将在
LoadModule rewrite\u module modules/mod\u rewrite.so
中找到这一行。在
httpd.conf
文件中,该文件将位于
conf
文件夹下。您需要从中删除哈希(#),然后重新启动apache服务

如果您希望在Tomcat中进行设置,那么我在示例项目中所做的就是将下面的代码添加到
webapps\ROOT\WEB-INF\WEB.xml
文件中

<?xml version="1.0" encoding="UTF-8"?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                      http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
  version="4.0"
  metadata-complete="true">

  <display-name>Welcome to Tomcat</display-name>
  <description>
     Welcome to Tomcat
  </description>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

   <error-page>
    <error-code>404</error-code>
    <location>/test/index.html</location>
  </error-page>
</web-app>

欢迎来到Tomcat
欢迎来到Tomcat
index.html
404
/test/index.html

此处
/test/index.html
test
是我的项目名称,您可以将其更改为您的项目名称,但请尝试使用project web.xml以避免其他项目重定向。在这种情况下,您可以直接在conf文件夹下的path

中添加
/index.html
,但没有这样的文件。我检查了很多次。事实上,在我提到的目录中没有类似于httpd.conf的文件。那么如何启用mod_重写呢?您有这种结构吗
conf/virtual hosts/default.conf
?或者在这里找到类似于
conf/Catalina/my.domain.com/rewrite.config
的东西,例如
my.domain.com
,或者您可以使用WAMP或Apache2代替TomcatI更新答案,它对其进行了测试。让我知道这是否有效
<?xml version="1.0" encoding="UTF-8"?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                      http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
  version="4.0"
  metadata-complete="true">

  <display-name>Welcome to Tomcat</display-name>
  <description>
     Welcome to Tomcat
  </description>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

   <error-page>
    <error-code>404</error-code>
    <location>/test/index.html</location>
  </error-page>
</web-app>