doutang2017 2017-11-23 22:37
浏览 13
已采纳

没有“.php”扩展名的空白页面

I'm currently been trying to figure out how to remove .php extension from URL bar. However when I remove .php it gives me a blank white page.

Could someone please be able to explain why this would be happening?

I've added to the php.ini: expose_php=Off

and also got this in my .htaccess:

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

Then started to write the following for 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;
        }
    }


?>

Example with .php:

enter image description here

Example without .php:

enter image description here

  • 写回答

3条回答 默认 最新

  • dounai9592 2017-12-11 18:23
    关注

    There is my htaccess code check if this work for you

    # 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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 有偿求数字经济对经贸的影响机制的一个数学模型,弄不出来已经快要碎掉了
  • ¥15 这个公式写进SIMULINK中的function模块的代码中应该是什么样的
  • ¥15 javaweb登陆的网页为什么不能正确连接查询数据库
  • ¥15 数学建模数学建模需要
  • ¥15 已知许多点位,想通过高斯分布来随机选择固定数量的点位怎么改
  • ¥20 nao机器人语音识别问题
  • ¥15 怎么生成确定数目的泊松点过程
  • ¥15 layui数据表格多次重载的数据覆盖问题
  • ¥15 python点云生成mesh精度不够怎么办
  • ¥15 QT C++ 鼠标键盘通信