简体   繁体   中英

Write .htaccess file to redirect url through index.php without the error object not found

this is my index.php file.

<?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;
}
?

i have virtually hosted this by xampp.My requirement is that i want the url path to be get printed. for example.i hosted this as www.salary.dev.if i type www.salary.dev/ibm, i want ibm to get printed.but when i type this i am getting 404 error.Then i got to know that we want to write .htaccess file for this.i dont know how to write.please help me to write the .htaccess file for routing which is not existing.please help me.Thanks in advance.

Mod rewrite should help.

.htaccess:

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

try it

.htaccess

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

index.php

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

Try this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM