2017-04-14 36 views
2

如果目錄或文件存在,我需要獲取url。 我的配置:如果目錄或文件存在,如何獲取url?

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} -f 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule .* ./user.php?action=$0 [QSA] 

我的PHP文件:

<?php 
    if (isset($_GET['action'])) { 
    echo $_GET['action']; 
    } 
    ?> 

回答

0

請嘗試用下面的代碼: -

$path = 'path/to/file_or_dir'; 
if (file_exists($path)){ 

    $url = (@$_SERVER["HTTPS"] == "on") ? "https://" : "http://"; 
    $url .=$_SERVER["SERVER_NAME"]. dirname($path); 
    echo $url; 

} 
相關問題