-1

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.

Pranav
  • 47
  • 8

3 Answers3

0

Mod rewrite should help.

.htaccess:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
vstelmakh
  • 742
  • 1
  • 11
  • 19
0

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'];
?>
Dhiarj Sharma
  • 328
  • 3
  • 12
0

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>
Massimiliano Kraus
  • 3,638
  • 5
  • 27
  • 47