Enable mod_rewrite in Windows for .htaccess to work












2















I want to run my Angular 6 app over Apache Tomcat server. But every time I reload when in deep link URL then it shows status 404 page not found.
So, for that, I included the .htaccess file in the root folder where my index.html is.
But still, it doesn't work because maybe the mod_rewrite is not enabled.



To enable mod_rewrite I was searching for httpd.conf file where I have to make the changes. But in my 'C:Program FilesApache Software FoundationTomcat 9.0' directory there is NO such file.



So how do i enable the mod_rewrite to make .htaccess work and reload my Angular app without an error?










share|improve this question





























    2















    I want to run my Angular 6 app over Apache Tomcat server. But every time I reload when in deep link URL then it shows status 404 page not found.
    So, for that, I included the .htaccess file in the root folder where my index.html is.
    But still, it doesn't work because maybe the mod_rewrite is not enabled.



    To enable mod_rewrite I was searching for httpd.conf file where I have to make the changes. But in my 'C:Program FilesApache Software FoundationTomcat 9.0' directory there is NO such file.



    So how do i enable the mod_rewrite to make .htaccess work and reload my Angular app without an error?










    share|improve this question



























      2












      2








      2


      1






      I want to run my Angular 6 app over Apache Tomcat server. But every time I reload when in deep link URL then it shows status 404 page not found.
      So, for that, I included the .htaccess file in the root folder where my index.html is.
      But still, it doesn't work because maybe the mod_rewrite is not enabled.



      To enable mod_rewrite I was searching for httpd.conf file where I have to make the changes. But in my 'C:Program FilesApache Software FoundationTomcat 9.0' directory there is NO such file.



      So how do i enable the mod_rewrite to make .htaccess work and reload my Angular app without an error?










      share|improve this question
















      I want to run my Angular 6 app over Apache Tomcat server. But every time I reload when in deep link URL then it shows status 404 page not found.
      So, for that, I included the .htaccess file in the root folder where my index.html is.
      But still, it doesn't work because maybe the mod_rewrite is not enabled.



      To enable mod_rewrite I was searching for httpd.conf file where I have to make the changes. But in my 'C:Program FilesApache Software FoundationTomcat 9.0' directory there is NO such file.



      So how do i enable the mod_rewrite to make .htaccess work and reload my Angular app without an error?







      apache .htaccess tomcat






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 14 '18 at 12:43









      Ploppy

      5,89322038




      5,89322038










      asked Nov 14 '18 at 12:35









      BorisBoris

      113




      113
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Tomcat doesn't use httpd.conf, that is an apache file. The location of the individual webapps are kept in their individual web.xml files, but the location of all the configs are in ../tomcat8/conf/server.xml and web.xml



          Try WAMP or Apache2 instead of Tomcat



          You need to direct the .htaccess file to load the index.html on each hit.



          like



          DirectoryIndex index.html
          RewriteEngine On
          RewriteCond %{REQUEST_FILENAME} !-s
          RewriteCond %{REQUEST_FILENAME} !-l
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteCond %{REQUEST_URI} !.(jpg|jpeg|png|gif|flv|mpeg|mpg|mp4)$
          RewriteRule ^.*$ bootstrap.html [NC,L]


          You will found this line in LoadModule rewrite_module modules/mod_rewrite.so in httpd.conf file, the file will be under the conf folder. you need to remove the hash(#) from it and then restart the apache services.



          If you want that setup in Tomcat, then what I did in sample project is added the below code in webappsROOTWEB-INFweb.xml file



          <?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>


          Here /test/index.html test is my project name, you can change it to yours but try to use the project web.xml to avoid other project redirection. and in that case you can directly add the /index.html in path






          share|improve this answer


























          • under conf folder there is no such file. I checked it many times. Infact there is no such file like httpd.conf in the directory i mentioned. So how do i enable the mod_rewrite?

            – Boris
            Nov 14 '18 at 13:05













          • Do you have this structure? conf/virtual-hosts/default.conf ?

            – Rohit.007
            Nov 14 '18 at 13:13











          • Or find something like conf/Catalina/my.domain.com/rewrite.config here my.domain.com is example

            – Rohit.007
            Nov 14 '18 at 13:20













          • Or you can use WAMP or Apache2 instead of Tomcat

            – Rohit.007
            Nov 14 '18 at 13:27











          • I don't have this route - conf/virtual-hosts/default.conf, neither this- conf/Catalina/my.domain.com/rewrite.config.

            – Boris
            Nov 14 '18 at 13:32













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300392%2fenable-mod-rewrite-in-windows-for-htaccess-to-work%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Tomcat doesn't use httpd.conf, that is an apache file. The location of the individual webapps are kept in their individual web.xml files, but the location of all the configs are in ../tomcat8/conf/server.xml and web.xml



          Try WAMP or Apache2 instead of Tomcat



          You need to direct the .htaccess file to load the index.html on each hit.



          like



          DirectoryIndex index.html
          RewriteEngine On
          RewriteCond %{REQUEST_FILENAME} !-s
          RewriteCond %{REQUEST_FILENAME} !-l
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteCond %{REQUEST_URI} !.(jpg|jpeg|png|gif|flv|mpeg|mpg|mp4)$
          RewriteRule ^.*$ bootstrap.html [NC,L]


          You will found this line in LoadModule rewrite_module modules/mod_rewrite.so in httpd.conf file, the file will be under the conf folder. you need to remove the hash(#) from it and then restart the apache services.



          If you want that setup in Tomcat, then what I did in sample project is added the below code in webappsROOTWEB-INFweb.xml file



          <?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>


          Here /test/index.html test is my project name, you can change it to yours but try to use the project web.xml to avoid other project redirection. and in that case you can directly add the /index.html in path






          share|improve this answer


























          • under conf folder there is no such file. I checked it many times. Infact there is no such file like httpd.conf in the directory i mentioned. So how do i enable the mod_rewrite?

            – Boris
            Nov 14 '18 at 13:05













          • Do you have this structure? conf/virtual-hosts/default.conf ?

            – Rohit.007
            Nov 14 '18 at 13:13











          • Or find something like conf/Catalina/my.domain.com/rewrite.config here my.domain.com is example

            – Rohit.007
            Nov 14 '18 at 13:20













          • Or you can use WAMP or Apache2 instead of Tomcat

            – Rohit.007
            Nov 14 '18 at 13:27











          • I don't have this route - conf/virtual-hosts/default.conf, neither this- conf/Catalina/my.domain.com/rewrite.config.

            – Boris
            Nov 14 '18 at 13:32


















          0














          Tomcat doesn't use httpd.conf, that is an apache file. The location of the individual webapps are kept in their individual web.xml files, but the location of all the configs are in ../tomcat8/conf/server.xml and web.xml



          Try WAMP or Apache2 instead of Tomcat



          You need to direct the .htaccess file to load the index.html on each hit.



          like



          DirectoryIndex index.html
          RewriteEngine On
          RewriteCond %{REQUEST_FILENAME} !-s
          RewriteCond %{REQUEST_FILENAME} !-l
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteCond %{REQUEST_URI} !.(jpg|jpeg|png|gif|flv|mpeg|mpg|mp4)$
          RewriteRule ^.*$ bootstrap.html [NC,L]


          You will found this line in LoadModule rewrite_module modules/mod_rewrite.so in httpd.conf file, the file will be under the conf folder. you need to remove the hash(#) from it and then restart the apache services.



          If you want that setup in Tomcat, then what I did in sample project is added the below code in webappsROOTWEB-INFweb.xml file



          <?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>


          Here /test/index.html test is my project name, you can change it to yours but try to use the project web.xml to avoid other project redirection. and in that case you can directly add the /index.html in path






          share|improve this answer


























          • under conf folder there is no such file. I checked it many times. Infact there is no such file like httpd.conf in the directory i mentioned. So how do i enable the mod_rewrite?

            – Boris
            Nov 14 '18 at 13:05













          • Do you have this structure? conf/virtual-hosts/default.conf ?

            – Rohit.007
            Nov 14 '18 at 13:13











          • Or find something like conf/Catalina/my.domain.com/rewrite.config here my.domain.com is example

            – Rohit.007
            Nov 14 '18 at 13:20













          • Or you can use WAMP or Apache2 instead of Tomcat

            – Rohit.007
            Nov 14 '18 at 13:27











          • I don't have this route - conf/virtual-hosts/default.conf, neither this- conf/Catalina/my.domain.com/rewrite.config.

            – Boris
            Nov 14 '18 at 13:32
















          0












          0








          0







          Tomcat doesn't use httpd.conf, that is an apache file. The location of the individual webapps are kept in their individual web.xml files, but the location of all the configs are in ../tomcat8/conf/server.xml and web.xml



          Try WAMP or Apache2 instead of Tomcat



          You need to direct the .htaccess file to load the index.html on each hit.



          like



          DirectoryIndex index.html
          RewriteEngine On
          RewriteCond %{REQUEST_FILENAME} !-s
          RewriteCond %{REQUEST_FILENAME} !-l
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteCond %{REQUEST_URI} !.(jpg|jpeg|png|gif|flv|mpeg|mpg|mp4)$
          RewriteRule ^.*$ bootstrap.html [NC,L]


          You will found this line in LoadModule rewrite_module modules/mod_rewrite.so in httpd.conf file, the file will be under the conf folder. you need to remove the hash(#) from it and then restart the apache services.



          If you want that setup in Tomcat, then what I did in sample project is added the below code in webappsROOTWEB-INFweb.xml file



          <?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>


          Here /test/index.html test is my project name, you can change it to yours but try to use the project web.xml to avoid other project redirection. and in that case you can directly add the /index.html in path






          share|improve this answer















          Tomcat doesn't use httpd.conf, that is an apache file. The location of the individual webapps are kept in their individual web.xml files, but the location of all the configs are in ../tomcat8/conf/server.xml and web.xml



          Try WAMP or Apache2 instead of Tomcat



          You need to direct the .htaccess file to load the index.html on each hit.



          like



          DirectoryIndex index.html
          RewriteEngine On
          RewriteCond %{REQUEST_FILENAME} !-s
          RewriteCond %{REQUEST_FILENAME} !-l
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteCond %{REQUEST_URI} !.(jpg|jpeg|png|gif|flv|mpeg|mpg|mp4)$
          RewriteRule ^.*$ bootstrap.html [NC,L]


          You will found this line in LoadModule rewrite_module modules/mod_rewrite.so in httpd.conf file, the file will be under the conf folder. you need to remove the hash(#) from it and then restart the apache services.



          If you want that setup in Tomcat, then what I did in sample project is added the below code in webappsROOTWEB-INFweb.xml file



          <?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>


          Here /test/index.html test is my project name, you can change it to yours but try to use the project web.xml to avoid other project redirection. and in that case you can directly add the /index.html in path







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 15 '18 at 16:06

























          answered Nov 14 '18 at 12:41









          Rohit.007Rohit.007

          1,6312419




          1,6312419













          • under conf folder there is no such file. I checked it many times. Infact there is no such file like httpd.conf in the directory i mentioned. So how do i enable the mod_rewrite?

            – Boris
            Nov 14 '18 at 13:05













          • Do you have this structure? conf/virtual-hosts/default.conf ?

            – Rohit.007
            Nov 14 '18 at 13:13











          • Or find something like conf/Catalina/my.domain.com/rewrite.config here my.domain.com is example

            – Rohit.007
            Nov 14 '18 at 13:20













          • Or you can use WAMP or Apache2 instead of Tomcat

            – Rohit.007
            Nov 14 '18 at 13:27











          • I don't have this route - conf/virtual-hosts/default.conf, neither this- conf/Catalina/my.domain.com/rewrite.config.

            – Boris
            Nov 14 '18 at 13:32





















          • under conf folder there is no such file. I checked it many times. Infact there is no such file like httpd.conf in the directory i mentioned. So how do i enable the mod_rewrite?

            – Boris
            Nov 14 '18 at 13:05













          • Do you have this structure? conf/virtual-hosts/default.conf ?

            – Rohit.007
            Nov 14 '18 at 13:13











          • Or find something like conf/Catalina/my.domain.com/rewrite.config here my.domain.com is example

            – Rohit.007
            Nov 14 '18 at 13:20













          • Or you can use WAMP or Apache2 instead of Tomcat

            – Rohit.007
            Nov 14 '18 at 13:27











          • I don't have this route - conf/virtual-hosts/default.conf, neither this- conf/Catalina/my.domain.com/rewrite.config.

            – Boris
            Nov 14 '18 at 13:32



















          under conf folder there is no such file. I checked it many times. Infact there is no such file like httpd.conf in the directory i mentioned. So how do i enable the mod_rewrite?

          – Boris
          Nov 14 '18 at 13:05







          under conf folder there is no such file. I checked it many times. Infact there is no such file like httpd.conf in the directory i mentioned. So how do i enable the mod_rewrite?

          – Boris
          Nov 14 '18 at 13:05















          Do you have this structure? conf/virtual-hosts/default.conf ?

          – Rohit.007
          Nov 14 '18 at 13:13





          Do you have this structure? conf/virtual-hosts/default.conf ?

          – Rohit.007
          Nov 14 '18 at 13:13













          Or find something like conf/Catalina/my.domain.com/rewrite.config here my.domain.com is example

          – Rohit.007
          Nov 14 '18 at 13:20







          Or find something like conf/Catalina/my.domain.com/rewrite.config here my.domain.com is example

          – Rohit.007
          Nov 14 '18 at 13:20















          Or you can use WAMP or Apache2 instead of Tomcat

          – Rohit.007
          Nov 14 '18 at 13:27





          Or you can use WAMP or Apache2 instead of Tomcat

          – Rohit.007
          Nov 14 '18 at 13:27













          I don't have this route - conf/virtual-hosts/default.conf, neither this- conf/Catalina/my.domain.com/rewrite.config.

          – Boris
          Nov 14 '18 at 13:32







          I don't have this route - conf/virtual-hosts/default.conf, neither this- conf/Catalina/my.domain.com/rewrite.config.

          – Boris
          Nov 14 '18 at 13:32






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300392%2fenable-mod-rewrite-in-windows-for-htaccess-to-work%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Xamarin.iOS Cant Deploy on Iphone

          Glorious Revolution

          Dulmage-Mendelsohn matrix decomposition in Python