2017-10-09 58 views
-1

這是我的index.php文件。寫入.htaccess文件以通過index.php重定向url,但沒有找到錯誤對象

<?php 

$url=getCurrentURL(); 
    $path=parse_url($url, PHP_URL_PATH); 

$a= str_replace('/', '', $path); 
    echo $a; 


    function getCurrentURL() 
{ 
    $currentURL = (@$_SERVER["HTTPS"] == "on") ? "https://" : "http://"; 
    $currentURL .= $_SERVER["SERVER_NAME"]; 

    if($_SERVER["SERVER_PORT"] != "80" && $_SERVER["SERVER_PORT"] != "443") 
    { 
     $currentURL .= ":".$_SERVER["SERVER_PORT"]; 
    } 

     $currentURL .= $_SERVER["REQUEST_URI"]; 
    return $currentURL; 
} 
? 

我已虛擬承載這個由xampp.My的要求是,我想要的URL路徑被打印。例如,我用www.salary.dev.if託管了這個,我輸入www.salary.dev/ibm,我想讓ibm打印。但是當我輸入這個時,我得到了404錯誤。然後我知道我們想寫這個.htaccess文件這個。我不知道如何寫。請幫助我編寫路由的.htaccess文件不存在。請幫助我。提前感謝。

+1

可能重複[重定向所有index.php htaccess](https://stackoverflow.com/questions/18406156/redirect-all-to-index-php-htaccess) – Philipp

+0

no use.any other。 – Pranav

+0

你是否需要處理錯誤文檔? –

回答

0

Mod重寫應該有幫助。

的.htaccess:

RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
+0

它不工作? – Pranav

+0

什麼不起作用?你看到了什麼錯誤? mod_rewrite模塊是否安裝在您的Web服務器上?你的.htaccess文件和index.php位於相同的目錄嗎? – vstelmakh

+0

mod_rewrite模塊已啓用。 .htaccess文件和index.php位於同一個文件夾中,提示404錯誤。 – Pranav

0

嘗試

的.htaccess

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?action=$1 [L] 

的index.php

<?php 
echo $_REQUEST['action']; 
?> 
+0

no.object再次找不到錯誤。 – Pranav

+0

在這裏檢查[鏈接](http://omr.dhirajsharma.com/old/Pranav) –

+0

這是相同的代碼。你已經提到過了。 – Pranav

0

試試這個:

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 
相關問題