Clean URLs
| Project: | ProjectPier |
| Version: | 0.8.5.x-dev |
| Component: | User interface |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Tim |
| Status: | patch - code needs review |
It would be nice to have clean URLs instead of index.php?c=controller&a=action¶m1=value1&active_project=2#32
I will attach a patch that still need some work but I would appreciate some testing done (it can break things easily...).
It will create URL in the form of
http://server/controllername/action/?params
or http://server/projectID/controller/action/?params
The position of project ID can be changed if you feel it would make more sense the other way. Some discussion about that on the dev mailing list.
To make it work (works only with Apache!)
- make sure that the mod_rewrite module is loaded in Apache
- apply the patch as you would for any other patch
- add the following line to config/config.php:
<?php
define('PRETTY_URL', true);
?>Make sure that mod_rewrite is loaded, otherwise Apache won't be happy with the .htaccess file that is now modified.
Also, if it doesn't work, you can set the variable PRETTY_URL to false. If you delete the line completely, on my machine, php evaluates PRETTY_URL to true by default...

Here is the patch.
Well, I forgot something important:
you need to modify .htaccess so that the rewrite rules are ok according to your installation.
The patch should write .htaccess with these two last lines:
RewriteRule ^([0-9]+)/([a-zA-z0-9]+)/([a-zA-z0-9]+)?/?$ /PHP/PP_pretty_url/index.php?c=$2&a=$3&active_project=$1 [QSA]
RewriteRule ^([a-zA-z0-9]+)/([a-zA-z0-9]+)?/?$ /PHP/PP_pretty_url/index.php?c=$1&a=$2 [QSA]
you will need to change /PHP/PP_pretty_url/ to whatever your PP installation is.
Here is a patch for review.
Changes since previous version:
* PRETTY_URL becomes CLEAN_URL
* the clean URLs include the Object Id if present: http://server/13/message/view/4/ to view the message of ID 4 in Project of ID 13
* the installation includes the ability to select or not the clean URL. That means no fiddling with the .htaccess or config.php files.
* the .htaccess file works even if the module isn't loaded, which means only one .htaccess file for all. And it's very easy to toggle the option through config.php afterwards.
Please have a look and let me know if you find any problems with it.
NB: to test it on an existing installation, you need to apply the patch and then modify .htaccess to match your base URL (under RewriteBase) and config.php to add
<?phpdefine('CLEAN_URL', true);
?>
I saw that I forgot to remove some stuff in the installation step 4 and that the search was not included.
I'll put a patch in the next couple of days that fixes that but you can still test this one for now ;-)
Here is the patch that I talked about.
Changes since 0.9:
- revert to acInstallation.class.php (a patch to move to ppInstallation.class.php will be created later)
- clean the final installation step (I had forgotten some superfluous printing...)
- made the search function use the clean URLs too.
If you have any comments on the .htaccess file, I'm eager to hear from you. I'm no expert in it, so there might be some more efficient way.
Anybody to test it? ;-)
Tim
We've been using the patch in my company for a couple of months with no problem. However, I would like somebody to review the code and test it. Thanks!