howto remove 'index.php' in urls

Author Message

Lachy Laycock

Tuesday 11 November 2003 4:00:53 am

Hi all,

I have read numerous accounts of people trying to remove the index.php and have followed all of the subsequent suggestions to no avail. So let me explain what i have:

I have ezPublish 3.2.2 installed into the root dir of my server. So that i can access it with www.myserver.com/. All URLs work with the index.php, in it but I want to remove it.

my /settings/override/site.ini.append.php contains the following:

MatchOrder=host
SiteAccessList[]
SiteAccessList[]=user

HostMatchMapItems[]=myserver.com:user
HostMatchMapItems[]=www.myserver.com:user

With this config i can access myserver.com/index.php/user/news/ but not myserver.com/user/news/ (it redirects me to the '/' root page)

The catch is that i donnot have access to httpd.conf and know that i cannot set any virtualhost directives.

But, do I really need to if it is installed to my root dir?

Also, in this configuration, I don't see there is any infomation to remove the 'index.php' part from the URL...

it's all very confusing :S

Any advice would very much appreciated.

Tristan Koen

Tuesday 11 November 2003 4:38:48 am

I have the same problem.
The only way you can fix it afaik is to put your rewrite rules in httpd.conf.
As soon as you put them into .htaccess, you are stuck with the index.php bit.

I have logged a bug report, but I doubt that it is high on anyones todo list.

My advice would be to ask your webserver admin/ISP/hosting provider/whatever to put the rewrite rules into your httpd.conf for you.

Jonny Bergkvist

Tuesday 11 November 2003 6:14:17 am

You need to have this RewriteRule in your httpd.conf:

RewriteRule !\.(gif|css|jpg|png|jar|js|html)$ /index.php

Jonny

Willie Seabrook

Tuesday 11 November 2003 9:04:06 pm

You also need to have both mod_rewrite *and* mod_proxy compiled and enabled don't you so that you can use the RewriteRule parameter [P] instead of [R], thereby 'hiding' the index.php????

Regards,
Willie

Lachy Laycock

Tuesday 11 November 2003 9:50:01 pm

Thanks for all your suggestions.

Given my limited access to Apache configurations (being on a shared server), I have decided that the best solution so far seems to be in using mod_rewrite (given no mod_proxy). I created the following rules that do the job i want to do:

RewriteRule !(^/?user/?.*$|^/?admin/?.*$|\.(gif|css|jpe?g|png|js|asf|avi|wmv|swf|xsl|jar|html))$ index.php

RewriteRule ^/?(user|admin)/?(.*)$ index.php/$1/$2

this allows me to have urls like:

myserver.com/user/news/
&
myserver.com/admin/setup/cache/

etc.

The new issue becomes, how do i change the urls within the site?

Exisiting ones still work with the ezurl operator, like:
myserver.com/index.php/user/news/

But using the ezroot operator is no good, eg:
myserver.com/news/

So, I assume i should create a new operator to use with url_alias that prepends the SiteAccess name to the url_alias value.

This seems like quite a hassel for something that should be already configurable within the ini settings.

Can anyone think of a better, elegent solution to this hack?

Regards,
Lachy

Lachy Laycock

Wednesday 12 November 2003 12:14:49 am

In response to myself:

I have created a temporary solution/hack that does the job:

In my .htaccess i have:

RewriteRule !(^/?user/?.*$|^/?admin/?.*$|\.(gif|css|jpe?g|png|js|asf|avi|wmv|swf|xsl|jar|html))$ index.php

RewriteRule ^/?(admin|user)/?(.*)$ index.php/$1/$2

This effectively removes the index.php from the URLs.

Next to remove the 'index.php' from the links within the templates i created a template operator called 'ezniceurl', this replaces the 'ezurl' operator. The code from the modify function in that class is:

function modify( &$tpl, &$operatorName, &$operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters )
{
require_once('lib/ezutils/classes/ezini.php');
require_once('lib/ezutils/classes/ezsys.php');

$ini = eZINI::instance();
eZSys::init( $ini );

// This siteAccessName eg: 'user' or 'admin'
$siteAccessName = $GLOBALS['eZCurrentAccess']['name'];

// append a separator if needed
if(substr($siteAccessName,-1)!=eZSys::FileSeparator() and $operatorValue[0]!=eZSys::FileSeparator())
$siteAccessName .= eZSys::FileSeparator();

$operatorValue = eZSys::wwwDir() .
eZSys::FileSeparator().
$siteAccessName .
$operatorValue;
}

(To find out how to make an operator check out the ones in the contributions section)

Very simple. It just appends the current siteAccess name to the ezroot value.

I am still not convinced this is a usefull solution, but for time being I am going to run with it, for lack of a better solution.

Regards,
Lachy

Simion Ward

Sunday 23 November 2003 11:40:33 am

Has anyone managed to to this - remove the 'index.php' part of the URL?

I've almost had-it with this!!!! I need to sort it out as I have recently purchased a license for the OE and cannot get it to work.......

I've tried all the suggestions through out this forum with no success - only frustrations and wasted time!!!!

Lachy Laycock

Sunday 23 November 2003 5:14:15 pm

My last reply to this thread outline the steps for removing the 'index.php' in the URL. Have you tried this? It is working for me.

Simion Ward

Monday 24 November 2003 12:49:19 am

Well, well ,well...... It works !!!!! Ez - you should take this 'hack' and .htaccess rewrite rule into consideration as it works perfectly for websites that are on shared servers with limitedd access to config files.

It also allows the Online editor to work correctly.

Thanks!!!

Lachy Laycock

Monday 24 November 2003 1:44:02 am

Simion,
I am glad you got it to work. But i do need to point out some of the limitations with this 'hack'.

Depending on your config, in order to truely remove all instances you will need to do a search-&-replace for all template in your dir and the design/standard dir. This creates some problems in the admin section.

In particular, the redirects after objects removal, submitting a newly published item etc etc break.... and I have not worked out how to fix this yet. This is something I am just living with.

My recommendation is to leave the standard directory as is and suffice with the index.php in your admin section and just override any instances of ezurl on your frontend that are coming from the design/standard/templates dir.

I do agree that this was way to hard to do. It should be something very simply configurable in the settings/* dir - maybe it is and no-one has pointed that out yet...

Simion Ward

Monday 24 November 2003 3:14:25 am

Lachy,

Thanks for that, I was just starting to consider the adverse effects the hack may have. Surely the "ezUrl" datatype could be modified directly. This would then cascade through the entire system, reducing work needed to 'find & replace'?

Lachy Laycock

Monday 24 November 2003 4:02:59 am

Indeed, it possible could be a better solution. But I felt queezy at the thought of hacking the files under kernel/ and or lib/ made me think twice. If were to do that then upgradeing version would be a big and I don't know how deep rabbit hole goes in terms of interdependancy goes with these things...

What would be nice is if the ez team slated some patches for the related kernel+libs files for a future release to support this.

I guess if some-one should propose a patch it's chances of adoption would be much higher...

But who knows how many ppl even consider this important? you + me = 2...

Andrew Wigglesworth

Sunday 08 February 2004 11:03:36 am

I'm just living with it, what's so bad about the "index.php" bit anyway?

Jeroen Sangers

Friday 12 May 2006 10:35:17 am

@Lachy: I tried to implement your solution but need some more guidance. Can you maybe send me your files, or point me to instrauction on where to paste your code?

Marc Boon

Saturday 13 May 2006 7:45:49 am

To remove index.php from ezurl generated urls put the following in your site.ini.append.php:

[SiteAccessSettings]
ForceVirtualHost=true

Then you can use mod_rewrite rules in .htaccess to prepend all urls with index.php? as described above.
There's no need to hack any kernel files.

Jeroen Sangers

Wednesday 17 May 2006 9:36:24 am

I have placed the code above in my siteaccess override and activated the rewrite rules, but the links in the pages produced by eZ Publish still show the index.php part.

I am now going through all my templates to change the ezurl operator into ezroot, which is a lot of work.

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.