eZ Publish Dev Tip #1 – Removing index.php

Ok, this one seems to popup in the forums just all too often, and it’s not an easy one to address – because a lot depends on your server environment and setup.

Removing index.php is done through Apache mod_rewrite which in turn interprets your URLs and passes them through index.php silently while everything looks pretty in your browser address bar. In order to get this working on your site you need to do the following.

1. Locate .htaccess_root in your root eZ Publish directory, this helpful file has a default set of htaccess rules to set you on your way.

2. Rename .htaccess_root to .htaccess, or paste the contents of the file into your VirtualHost configuration.

At this point in time your new URLS should hopefully work, but in many cases won’t. eZ Publish is meant to detect your virtual hosting configuration but this doesn’t always work. Never fear, we can force that option through the eZ Publish configuration files.

3. Edit settings/override/site.ini.append.php and under the [SiteAccessSettings] block add the line

ForceVirtualHost=true

Now you should hopefully be seeing much nicer URLs.

What about my old URLs?

If you have been using your eZ Publish installation already then search engines may have already indexed your content with the index.php in the URL. In this case all those existing records will bounce as errors. This is never good for your search rankings, so with some extra mod_rewrite magic in your .htaccess you can fix that up at the same time.

RewriteRule ^/index\.php/(.*)$ /$1 [L,R=301]

This should hopefully get you up and running with nice URLs. This guide is specifically for those running Apache, which is recommended for eZ Publish installations. If you choose to run a different webserver then modify the mod_rewrite rules and configuration to specifically suit your own webserver options.


 
 
 
  • http://covertocover.co.nz mike

    How do I apply this to the cover to cover site which I just applied the above to, however the old index.php/ pages don’t seem to work as I had planned, can you have a look at the .htaccess that I am using to see if its got all the correct parts. Perhaps you can give us an example in your blog to copy from?

    Thanks, Mike

  • http://covertocover.co.nz mike

    sorted now thank you :)

blog comments powered by Disqus