Skip to content

ng build fails to copy .htaccess to dist folder #4607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gandra opened this issue Feb 10, 2017 · 12 comments
Closed

ng build fails to copy .htaccess to dist folder #4607

gandra opened this issue Feb 10, 2017 · 12 comments

Comments

@gandra
Copy link

gandra commented Feb 10, 2017

ng build does not copy .htaccess to dest dir. I have tried to put .htaccess in both src and src/assets folder but in both cases .htaccess does not appears in dist folder.
Here are more details about:

OS?

Linux Mint 18.1 “Serena”

Versions.

angular-cli: 1.0.0-beta.28.3
node: 7.5.0
os: linux x64
@angular/common: 2.4.7
@angular/compiler: 2.4.7
@angular/core: 2.4.7
@angular/forms: 2.4.7
@angular/http: 2.4.7
@angular/platform-browser: 2.4.7
@angular/platform-browser-dynamic: 2.4.7
@angular/router: 3.4.7
@angular/compiler-cli: 2.4.7

Repro steps.

ng new angular-cli-test
cp kibernum-dnc-client/src/.htaccess angular-cli-test/src/
cd angular-cli-test

ng build
ls -la dist/

mv src/.htaccess src/assets/
ng build
ls -la dist/

The log given by the failure.

There is no log error. Errror is that I expect that file .htaccess is copied in dist folder.

@filipesilva
Copy link
Contributor

When you put it in src/assets/.htaccess, it will be copied into dist/assets/.htaccess.

If you want it to be in dist/.htaccess, then you should be in src/.htaccess AND you need to add it to angular-cli.json in the assets array (like favicon.ico).

@gandra
Copy link
Author

gandra commented Feb 10, 2017

@filipesilva ,
in such case .htaccess is copied in assets/.htaccess.
I want to have assets in the root of dest folder.

If you think that it works can you give me the gist of your angular-cli.json file?

Here is my gist

@filipesilva
Copy link
Contributor

Change this bit:

      "assets": [
        "assets",
        "favicon.ico"
      ],

to

      "assets": [
        "assets",
        "favicon.ico",
        ".htaccess"
      ],

@gandra
Copy link
Author

gandra commented Feb 10, 2017

Now works. Thanks!
So, for others as reference here. is fix:

  1. Put .htaccess in src folder (final path for is src/.htaccess)
  2. Have something similar to this:
            "assets": [
                "assets",
                "assets/images/favicon.ico",
                ".htaccess"
            ],

Kudos to @filipesilva !

@bkdotcom
Copy link

unrelated... why are files in my assets folder ending up in
/dist and in /dist/assets ?

@ghost
Copy link

ghost commented Oct 11, 2017

Hey @filipesilva , can you please let me know what should be the content of .htaccess?

I tried this, but of no use:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>

I have set <base href="http://146.148.47.134/mm-coming-soon/">

Need your guidance.

@javierojeda94
Copy link

@arun-awnics I know this may be late but this is my .htaccess file:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^(.*) index.html [NC,L]
</IfModule>

But in my case, I have set <base href="/">

Hope this helps.

@sandipsanap
Copy link

sandipsanap commented Jun 19, 2018

i have deployed the angular project on apache server and i have added .htaccess file in src folder but when i am refreshing the page at that time i am getting 404 error.

@bleuscyther
Copy link

@sandipsanap try with RewriteBase /
you can change it to /dist for example or the name of your sub_directory

@jbkhellas
Copy link

I know this might sound silly but angular.json has two sections, one for test and one for build. So add the entries to the correct one! :-)

@ahmadraza-gh
Copy link

I have generated the .htaccess file. Now I want to make changes in .htaccess file while building the angular build. currently I have the following in .htaccess file.

RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]

# If the requested resource doesn't exist, use index.html
RewriteRule ^ /test/index.html

I need to change the last line of this file RewriteRule ^ /test/index.html.
How can i achieve it.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants