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条)

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法