Using .htaccess to make all .html pages to run as .php files?

前端 未结 16 1472
忘了有多久
忘了有多久 2020-11-22 00:41

I need to run all of my .html files as .php files and I don\'t have time to change all of the links before our presentation tomorrow. Is there any way to \"hack\" this with

相关标签:
16条回答
  • 2020-11-22 01:44

    Create a .htaccess file at the root of your website and add this line:

    [Apache2 @ Ubuntu/Debian: use this directive]

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

    Or, from comment below:

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

    If your are running PHP as CGI (probably not the case), you should write instead:

    AddHandler application/x-httpd-php .html .htm 
    
    0 讨论(0)
  • 2020-11-22 01:44
    AddHandler application/x-httpd-php .php .html .htm
    // or
    AddType application/x-httpd-php .php .htm .html
    
    0 讨论(0)
  • 2020-11-22 01:44

    None of the answers posted here worked for me.

    In my case the problem was, by the one hand, that the .conf file (/etc/apache2/sites-available/default-ssl.conf or /etc/apache2/sites-available/000-default.conf) did not contain the directive AllowOverride All for the site directory, which caused the .htaccess to not been processed. To solve this, add:

    <Directory /var/www/html/>
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
    </Directory>
    

    On the other hand, the problem was that the .htaccess was created by the root user, and therefore the apache user could not read it. So, changing the file owner solved definitely the problem:

    chown www-data:www-data .htaccess
    
    0 讨论(0)
  • 2020-11-22 01:45

    In My Godaddy Server the following code worked

    Options +ExecCGI
    AddType application/x-httpd-php .php .html
    AddHandler x-httpd-php5 .php .html
    
    0 讨论(0)
提交回复
热议问题