删除的.php文件扩展名.htaccess文件(GoDaddy的)文件扩展名、文件、php、GoDaddy

2023-09-02 09:36:56 作者:倾世璃歌

这是我的命,因为我觉得如果我做正确的一切。 我看了看这个网站的其他职位,但没有aveil:

This is killing me because I feel as if I am doing everything correctly. I've looked at the other posts on this site but to no aveil:

我想www.mysite.com/about.php~~V仅仅是www.mysite.com/about

I want www.mysite.com/about.php to just be www.mysite.com/about

我创建一个.htaccess文件并把它放在我的服务器的根目录。 我使用的Linux共享托管。 PHP版本5.2(GoDaddy的主机)

I created an .htaccess file and placed it in the root of my server. I am using linux shared hosting. Php version 5.2 (godaddy hosting)

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php

看来这code应能正常工作,但由于某些原因,它没有。我得到一个404错误,当我尝试浏览到的网页不带.php扩展。

It seems that this code should work properly, but for some reason it does not. I get a 404 error when I try to navigate to a page without the .php extension.

下面是我的标记过:

<nav>
        <div class="container">
            <ul>
                <li><a href="index.php" <?php if (strpos($_SERVER['PHP_SELF'], 'index.php')) echo 'class="current-nav"';?>>home</a></li>
                <li><a href="about.php">about</a></li>
                <li><a href="services">our services</a></li>
                <li><a href="portfolio" <?php if (strpos($_SERVER['PHP_SELF'], 'portfolio.php')) echo 'class="current-nav"';?>>portfolio</a></li>
                <li><a href="testimonials" <?php if (strpos($_SERVER['PHP_SELF'], 'testimonials.php')) echo 'class="current-nav"';?>>testimonials</a></li>
                <!--<li><a href="#">client area</a></li>-->
                <li><a href="contact" <?php if (strpos($_SERVER['PHP_SELF'], 'contact.php')) echo 'class="current-nav"';?>>Contact</a></li>
                <li><a href="order" <?php if (strpos($_SERVER['PHP_SELF'], 'order.php')) echo 'class="current-nav"';?>><strong>Free Quote</strong></a></li>
            </ul>
        </div>
    </nav><!--/navigation--> 

您可以看到我尝试使用链接中的PHP扩展,并没有也试过。用PHP扩展的链接进入页面,但不删除的扩展。

You can see I tried using the php extension in the link and also tried without. The links with the php extension go to the page, but don't remove the extension.

我做了一个测试,看看module_rewrite被投入一些垃圾,并返回500错误启用。

I did a test to see if module_rewrite was enabled by putting in some garbage and returning a 500 error.

这是我的命。任何帮助将大大AP preciated。

This is killing me. ANy help would be greatly appreciated.

推荐答案

使用这种$ C $下隐藏/删除的.php 扩展:

Use this code for hiding/removing .php extension:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}s([^.]+).php [NC]
RewriteRule ^ %1 [R,L,NC]

## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]