Reputation: 8705
Without a possibility to access .htaccess I find myself in a creative impasse. There is no mod_rewriting for me. Nevertheless, I want to be able to do the nice stuff like:
http://www.example.com/Blog/2009/12/10/
http://www.example.com/Title_Of_This_Page
What are my alternatives?
In respond to the answers:
http://www.example.com/index.php/Blog/
is a known technique but I don't prefer it. Is shows the php so to say.Upvotes: 10
Views: 13727
Reputation: 2376
I know this question is very old but I didn't see anyone else suggest this possible solution...
You can get very close to what you want just by adding a question mark after the domain part of the URL, ie;
http://www.example.com/?Blog/2009/12/10/
http://www.example.com/?Title_Of_This_Page
Both of the above HTTP requests will now be handled by the same PHP
script;
www.example.com/index.php
and in the index.php
script, $_SERVER['REQUEST_URI']
for the two pages above will be respectively;
Blog/2009/12/10/
Title_Of_This_Page
so you can handle them however you want.
Upvotes: 7
Reputation: 31
You can write a URI class which parses the user-friendly URL you defined.
Upvotes: 1
Reputation: 26061
If you omit a trailing slash, Apache will serve the first file [alphabetically] which matches that name, regardless of the extension, at least on the 2 servers I have access to.
I don't know how you might use this to solve your problem, but it may be useful at some point.
For example if
http://www.somesite.com/abc.html
and http://www.somesite.com/abc.php
both exist and http://www.somesite.com/abc
is requested, http://www.somesite.com/abc.html
will be served.
Upvotes: 3
Reputation: 124317
If the MultiViews
option is enabled or you can convince whoever holds the keys to enable it, you can make a script called Blog.php that will be passed requests to example.com/Blog/foo
and get '/foo' in the $_SERVER['PATH_INFO']
.
Upvotes: 0
Reputation: 1171
The only way is to use custom 404 page. You have no possibility to interpret extensionless files with PHP interpreter without reconfiguring the web server's MIME-types. But you say that you can't edit even .htaccess, so there's no other way.
Upvotes: 2
Reputation: 4078
You can also have urls like
http://domain.com/index.php/Blog/Hello_World
out of the box with PHP5. You can then read the URL parameters using
echo $_SERVER['PATH_INFO'];
Remember to validate/filter the PATH_INFO and all other request variables before using them in your application.
Upvotes: 7
Reputation: 39148
A quite simple way is to:
.htaccess
$_SERVER
and see if it corresponds to any resultheader()
and include index.phpUpvotes: 3
Reputation: 17846
If you've the permissions to set custom error documents for your server you could use this to redirect 404 requests.
E.g. for Apache (http://httpd.apache.org/docs/2.0/mod/core.html#errordocument)
ErrorDocument 404 /index.php
In the index.php you then can proceed your request by using data from the $_SERVER array.
Upvotes: 12