views:

461

answers:

4

Hi to all, I'm aware of all the canonical ways of getting clean URLs (www.mysite.com/getarticle?a=123 vs www.mysite.com/getarticle/123).

Those solutions include mod_rewrite, force_type and various configurations of apache, mostly.

Since I don't have access to such config on my shared hosting, is there any solution / hack to work around the limitation and get the work done? Thanks.

+3  A: 

Yes.

If you call the script via a, www.example.com/index.php/my/path/here you can get the request path pretty easily from $_SERVER. I personally use $_SERVER['PHP_SELF'] but there are several to choose from depending on the version of PHP that you use.

The Wicked Flea
+2  A: 

Just to be certain - are you sure you can't use mod_rewrite?

If it's installed/enabled on the shared hosting server, you can just put a .htaccess file in your public_html directory with your rewrite rules in it. No need to change the actual apache configuration.

Eric Petroelje
A: 

Honestly, you probably have access and just don't know it, search for 'htaccess' in your host's help area

Andrew G. Johnson
A: 

You cannot use other URLs than the system-dependent if the system cannot handle them correctly. And the native behavior of webservers is to map the requested URL path one-on-one onto the file system.

But most web servers provide some features to allow such things, to map requested URL path with the assistance of particular rules onto the file system.

Apache for example has AcceptPathInfo to append additional path segments after a URL path that already references an existing file while preserving that information (see PATH_INFO envirnoment variable) and mod_rewrite for even more functionality.

Gumbo
Apparently, AcceptPathInfo is off by default for normal apache requests, but on by default for mod_php and most CGI handlers.
Frank Farmer