Jump to content

I'm trying to have both .php and .html on my website, my .html works as I want it to where it doesent show the ending in the url. but for the .php you need to type the .php and if you don't it downloads the .php file as if it was a file.

How do you fix this?

I'm using Nginx.

My config ( I know it's messy but thats becouse I little knowlage of how this works )

  location ~ /\. {
    deny all;
  }
  location ~ /\.well-known\/acme-challenge {
    allow all;
  }

  location / {
    try_files  $uri/index.html $uri.html $uri/ $uri =404;
  }
  location ~ \.php$ {
   try_files $uri/index.php $uri.php $uri/ $uri @exstensionless-php =404;
   fastcgi_split_path_info ^(.+\.php)(/.+)$;
   fastcgi_pass unix:/run/php/php7.0-fpm.sock;
   fastcgi_index index.php;
   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
   include fastcgi_params;
  }
  location @extensionless-php {
    rewrite ^(.*)$ $1.php last;
  }

  rewrite ^(/.*)\.html(\?.*)?$ $1$2 permanent;
  rewrite ^/(.*)/$ /$1 permanent;

  index index.html;
  try_files $uri/index.php $uri.php $uri/index.html $uri.html $uri/ $uri =404;
  location /admin/ {
    rewrite ^(/.*)\.html(\?.*)?$ $1$2 permanent;
    rewrite ^/(.*)/$ /$1 permanent;
    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/.htpasswd;
    index index.html;
    try_files $uri/index.html $uri.html $uri/ $uri =404;
  }

 

Back-end developer, electronics "hacker"

Link to comment
https://linustechtips.com/topic/678956-html-and-php-nginx-config/
Share on other sites

Link to post
Share on other sites

http://stackoverflow.com/questions/20105029/include-php-file-into-html-file

Quote

In order to get the PHP output into the HTML file you need to either:

  1. Change the extension of the HTML to file to PHP and include the PHP from there (simple)
  2. Load your HTML file into your PHP as a kind of template (a lot of work)
  3. Change your environment so it deals with HTML as if it was PHP (bad idea)
Quote

Create a .htaccess file in directory and add this code to .htaccess file


AddHandler x-httpd-php .html .htm

or


AddType application/x-httpd-php .html .htm

It will force Apache server to parse HTML or HTM files as PHP Script

The second quote is doing what the first quote said was a bad idea.

The "right" way appears to be "Load your HTML file into your PHP as a kind of template (a lot of work)" but I'm no web developer.

The other "right" way to do it appears to be this:

Quote

Note that this could have a performance impact as this would cause ALL .html files to be run through PHP handler even if there is no PHP involved. So you might strongly consider using .php extension on these files and adding a redirect as necessary to route requests to specific .html URL's to their .php equivalents.

I would do it that way honestly. 

StackOverflow is indispensable. 

† Christian Member †

For my pertinent links to guides, reviews, and anything similar, go here, and look under the spoiler labeled such. A brief history of Unix and it's relation to OS X by Builder.

 

 

Link to post
Share on other sites

1 hour ago, Vitalius said:

http://stackoverflow.com/questions/20105029/include-php-file-into-html-file

The second quote is doing what the first quote said was a bad idea.

The "right" way appears to be "Load your HTML file into your PHP as a kind of template (a lot of work)" but I'm no web developer.

The other "right" way to do it appears to be this:

I would do it that way honestly. 

StackOverflow is indispensable. 

Yea I know all that, but I need to fix my config file to get it to work right.

Back-end developer, electronics "hacker"

Link to post
Share on other sites

8 minutes ago, Joveice said:

Yea I know all that, but I need to fix my config file to get it to work right.

Have you tried this? 

http://stackoverflow.com/questions/21911297/how-to-remove-both-php-and-html-extensions-from-url-using-nginx

† Christian Member †

For my pertinent links to guides, reviews, and anything similar, go here, and look under the spoiler labeled such. A brief history of Unix and it's relation to OS X by Builder.

 

 

Link to post
Share on other sites

46 minutes ago, Vitalius said:

Yea thats what I have tryed, but it mixes up with how I have it.

Back-end developer, electronics "hacker"

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×