空白页面没有" .php"延期

时间:2017-11-23 22:37:44

标签: php

我目前一直试图找出如何从网址栏中删除.php扩展名。但是当我删除.php时,它会给我一个空白页面。

有人可以解释为什么会发生这种情况吗?

我已添加到php.iniexpose_php=Off

并在.htaccess

中得到了这个
   # Return 404 if original request is /foo/bar.php
    RewriteCond %{THE_REQUEST} "^[^ ]* .*?\.php[? ].*$"
    RewriteRule .* - [L,R=404]

然后开始为URL编写以下内容:

<?php 
    function parseCurrentURL() {
        $pageURL = 'http';
        $pageURL .= "://";
        if ($_SERVER["SERVER_PORT"] != "80") {
            $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
        } else {
            $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
        }
        return $pageURL;
    }

    if(parse_url(parseCurrentURL(), PHP_URL_PATH)){
        $url = parse_url(parseCurrentURL(), PHP_URL_PATH);
        switch(substr($url, strrpos($url, '/') + 1)){
            case 'forums':

                break;
        }
    }


?>

.php的示例:

enter image description here

没有.php的示例:

enter image description here

3 个答案:

答案 0 :(得分:1)

我的htaccess代码检查是否适用于您

# Default directory
DirectoryIndex index.php

# ERROR FILES
RewriteEngine On
ErrorDocument 404 /page404.php
ErrorDocument 500 /page500.php

# Remove the need for www in Your URL
RewriteCond %{HTTP_HOST} ^xxxx.pt$ [NC]
RewriteRule (.*) http://www.xxxx.pt/$1 [R=301,L]

# Exclude administrador folder
RewriteRule ^(administrador)($|/) - [L]

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

# 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 [NC]
RewriteRule ^ %{REQUEST_URI}.php [L]

##Expire headers
<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On
# Default directive
ExpiresDefault "access plus 1 month"
# My favicon
ExpiresByType image/x-icon "access plus 1 year"
# Images
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
# CSS
ExpiresByType text/css "access plus 1 month"
# Javascript
ExpiresByType text/javascript "access plus 1 month"
</IfModule>

答案 1 :(得分:0)

使用apache .htaccess配置

可以解决问题
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

此处提供更多信息https://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/

答案 2 :(得分:0)

我目前在.htaccess中使用此代码删除扩展名.php,我从未得到空白页

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

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