0

I have a simple script:

index.php:

<?php

$path= $_SERVER['PATH_INFO'];

if($path)
  echo $path;
else
  echo "No Path Info";

?>

When I run it like so www.website.com/index.php it works. ie) www.website.com/index.php/hello will echo /hello

However, if I go to www.website.com/hello, I get a URL not found error when what I want is that /hello is echoed.

How do I make it so that index.php doesn't have to be present for PATH_INFO to work?!

moesef
  • 4,641
  • 16
  • 51
  • 68

3 Answers3

1

If you are using apache web server - write this rule in your .htaccess..

RewriteEngine on
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ /index.php/$1 [L]
V_K
  • 229
  • 1
  • 4
  • these rules don't seem to work for subdomains. Forexample, sudomain `mo.website.com` gives me a bad request. – moesef Mar 02 '13 at 01:50
  • now its working. very weird. I wrote exactly what you have there and it didnt work. I changed the rule and then changed it back and i did work. – moesef Mar 02 '13 at 02:10
1

you will have to rewrite in the url settings depending on what server you are using to use clean url's

check this http://wettone.com/code/clean-urls

something on these lines

RewriteEngine on
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ /index.php/$1 [L]
user1833222
  • 403
  • 2
  • 5
  • 8
  • these rules don't seem to work for subdomains. For example, sudomain `mo.website.com` gives me a bad request. – moesef Mar 02 '13 at 01:51
  • now its working. very weird. I wrote exactly what you have there and it didnt work. I changed the rule and then changed it back and it did work. – moesef Mar 02 '13 at 02:11
0

When a webpage is requested from a server. The server looks at the path (i.e. example.com/this/is/a/path) to figure out which file to serve and from where.

As I understand it, what you want to do is have your index.php handle all the requests. The way you would do this to use URL Rewriting.

Assuming you are using an apache web server, you can use something called *mod_rewrite* to do this. See more on mod_rewrite here.

For the specific rules to use, you probably want to use something like the code in V_K's answer.

Tomas Reimers
  • 3,234
  • 4
  • 24
  • 37