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

前端 未结 16 1452
忘了有多久
忘了有多久 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:27

    You may also use the H or T flag of mod_rewrite to force all .html files to be parsed by php handler :

    using H (Handler) flag:

     RewriteEngine on
    
    RewriteRule \.(html|htm)$ - [H=application/x-httpd-php5]
    

    using T (Type) flag :

     RewriteEngine on
    
    RewriteRule \.(html|htm)$ - [T=application/x-httpd-php5]
    

    Or you can add more extensions to the rule pattern seprated by a pipe | that you want to be parsed by php handler

    ex :

    RewriteRule \.(html|htm|txt|foo)$ - [T=application/x-httpd-php5]
    

    the example above will change the mime type of files that end with .html , .htm , .txt , .foo to php.

    Note : on some servers you will have to change php5 to php to get this example to work in handler string:

    Change it

    [T=application/x-httpd-php5]
    

    to

    [T=application/x-httpd-php]
    

提交回复
热议问题