使用.htaccess,如何在运行时更改文件扩展名

时间:2016-06-08 03:49:59

标签: .htaccess

我想创建一个使用PHP的网站,但不希望显示http://example.com/index.php这样的扩展程序,我有index.php个文件,但只想显示index.html,可能是.html别的东西..

我不知道该怎么做,请帮帮我。

2 个答案:

答案 0 :(得分:2)

您可以在站点根目录中使用这两个规则.htaccess:

<div class="dp-tab-1">
                                    <ul class="dp-tab-list row" id="myTab">
                                        <% if @project.package.has_background_ip == true %>
                                            <li class="col-md-2 col-xs-6 <%= 'active' if firstActiveTab == 1 %>" >
                                            <!-- <li class="col-md-2 col-xs-6 active" > -->
                                                <a href="#tab-content-first">
                                                    <span class="glyph-item" data-icon="&#xe043;"></span> 
                                                    <span>BACKGROUND INTELLECTUAL PROPERTY</span>
                                                </a>
                                            </li>
                                        <% end %>

                                        <% if @project.package.has_data == true %>    
                                            <li class="col-md-2 col-xs-6 <%= 'active' if firstActiveTab == 2 %>" >
                                            <!-- <li class="col-md-2 col-xs-6"> -->
                                                <a href="#tab-content-second">
                                                    <div class="glyph-item" data-icon="&#xe05c;"></div>
                                                    <span>DATA</span>
                                                </a>
                                            </li>
                                        <% end %>

                                        <% if @project.package.has_funding == true %>   
                                            <li class="col-md-2 col-xs-6 <%= 'active' if firstActiveTab == 3 %>" >
                                            <!-- <li class="col-md-2 col-xs-6"> -->
                                                <a href="#tab-content-third">
                                                    <div class="glyph-item" data-icon="&#xe04c;"></div>
                                                    <span>FUNDING</span>
                                                </a>
                                            </li>
                                        <% end %>

                                        <% if @project.package.has_materials == true %>   
                                            <li class="col-md-2 col-xs-6 <%= 'active' if firstActiveTab == 4 %>" >
                                            <!-- <li class="col-md-2 col-xs-6"> -->
                                                <a href="#tab-content-fourth">
                                                    <div class="glyph-item" data-icon="&#xe04c;"></div>
                                                    <span>MATERIALS</span>
                                                </a>
                                            </li>
                                        <% end %>

答案 1 :(得分:1)

.htaccess有一个非常简单的方法:

RewriteEngine on  
RewriteBase /

RewriteCond %{THE_REQUEST} (.*)\.php  
RewriteRule ^(.*)\.php $1.html [R=301,L]