1

I use this code to parse the URL

function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}

print_r(parse_url(curPageURL()));

echo parse_url($url, PHP_URL_PATH);

It work when the URL be like this :

test.com/index.php/aaa

It returns "index.php/aaa" but I dont want index.php be in the URL,I want the url to be like this, for example:

test.com/aaa

and then return "aaa" but it shows 404 error. How can I solve my issue? i think i must change something in ".htaccess" but if i change "index.php" instead 404 page ,there's no 404

Meraj
  • 35
  • 5

1 Answers1

1

You might need a URL rewrite. If you have apache server, in your .htaccess file, or vhosts definition file, you can try this:

RewriteEngine on

RewriteCond %{DOCUMENT_ROOT}%{SCRIPT_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{SCRIPT_FILENAME} !-f
RewriteRule ^/(.*)$ /index.php/$1 [L]

It tells the webserver to rewrite the URL if you type something in a browser that is neither a directory, nor a file, we run index.php file instead.

It rewrites test.com/aaa to test.com/index.php/aaa .

jacouh
  • 8,473
  • 5
  • 32
  • 43