Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pretty URLs without mod_rewrite, without .htaccess

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:

  • I'm building with php5
  • I don't have access to .htaccess
  • http://www.example.com/index.php/Blog/ is a known technique but I don't prefer it. Is shows the php so to say.
  • How would I create extensionless PHP-files? Would this do the trick?
  • How much would using the custom 404 technique hurt performance?
like image 504
Kriem Avatar asked Jun 10 '09 12:06

Kriem


People also ask

How rewrite URL in PHP?

Create a . htaccess file in your web servers test directory - or any other directory on which you want to make URL Rewriting active - and add the below given line to it. Now we have the rewrite engine turned on and Apache is ready to rewrite URLs for you.


2 Answers

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.

like image 124
Philippe Gerber Avatar answered Sep 24 '22 15:09

Philippe Gerber


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.

like image 36
Shoan Avatar answered Sep 21 '22 15:09

Shoan