2017-10-09 52 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> 
相关问题