How to include an .htaccess file wit Nuxt? - vue.js

I have a Nuxt.js app with an .htaccess file.
The problem is that when I execute nuxt generate in the terminal, my .htaccess file disappears. What can I do to include my .htaccess file when I execute nuxt generate?

You could put your .htaccess file into the /static directory, more info on that in the doc.
That way, you will have direct access to it once pushed to production.
Otherwise, you can also use this approach if you need something more customizable.

Related

Creating a dynamic .htaccess for a Vue app

I am currently building a Vue app which requires a .htaccess which includes the subdirectory (publicPath) that the app will be installed in.
Is there a 'builtin' way to create .htaccess in public/ or assets/ that is updated to include publicPath?
I've looked at the HtmlWebpackPlugin template handling of index.html, but this doesn't seem to have the option to modify other files.
Otherwise I guess I can run some custom JS as part of the build process.

How do I add a folder to run PHP scripts in Nuxt Project folder?

I have a working Nuxt website configured using Nginx web server.
What I want to do is that I want to run some demo PHP script from a folder called demo which is placed inside root folder of the project.
Now if I access it like this: http://mywebsite.com/demo/test.php
It works fine but If I add a folder with more scripts and css files like this
http://mywebsite.com/demo/todo_list/index.php
Here the index.php is loaded with some images, css and js files. But the page on browser only executes the php code. It can't load any resources like js, css and image files.
Basically I want this folder to be independent so I can do my research work from this folder making it completely independent from Nuxt.
How can I do this?
Nevermind, I figured out.
Just had to add one more rule inside nginx config file as below
# Demo Folder
location /demo/ {
try_files $uri $uri/ /index.php$is_args$args;
}

How to generate txt & xml files in nuxt SSR?

Is there any way of generating a Google : ads.txt file every time i build my SSR project?
There is a module called: sitemap-module from nuxt-community, it is used to generate a sitemap xml file, and that file can be accessed by http://domain.tls/sitemap.xml. and i want something like that.
So currently i'am achieving this by building the project, then manually put ads.txt it in : /var/www/site/.nuxt/dist/client/,
The problem with this is that everytime i rebuild the project i loose /var/www/site/.nuxt/dist/client/ folder then i have to add ads.txt file again.
I would like to know how i can hook up my code to tell nuxt to generate ads.txt file and put it in /var/www/site/.nuxt/dist/client/
Not sure if it makes sense, but i hope someone will understand.
Place your ads.txt file in a directory named static as mentioned here. All the contents of the static directory can be accessed via example.com/{filename.extension}
If you are not using nuxt.js and just using vue js, place it in a public directory right next to src directory.
Haven't found any way of solving this in nuxt, so i decided to redirect all https://domain.tld/ads.txt in Nginx configuration.
/etc/nginx/sites-available/default.conf
#redirect all txt request
location ~* ^.+.(txt)$ {
root /var/www/other.files/;
}
So i think i'll stick to it.

Nuxt how can I browse static file

I have a php file under of static folder.
How can i browse the php file?
I tried to use a proxy on config, but its not working
/pages
/static
test.php
How could i browse it
localhost:port/[proxy]/test.php
Thanks
I guess you would need a webserver to handle your .php file.
/static folder is for static content.
This is what i found in the documentation:
If you don't want to use Webpack assets from the assets directory, you can create and use the static directory (in your project root folder).
All included files will be automatically served by Nuxt and are
accessible through your project root URL. (static/favicon.ico will be
available at localhost:3000/favicon.ico)
https://nuxtjs.org/guide/assets/#static

Apache .htaccess gets overwritten all the time

I use the .htaccess file from apache2 in /var/www/html/, after a while the file gets overwritten with what seem to be a default config file and I don't know why..
I don't use Wordpress or any CMS.
Any idea?
The problem was cause by "grunt build" that would automatically create an .htaccess file for me...