1

I'm attempting to use Apache rewriterules to strip index.php from the url, but I've hit a brick wall.

The following urls currently resolve to their correct pages:

http://dev.morningstaronline.co.uk/index.php/content/view/full/215

http://dev.morningstaronline.co.uk/content/view/full/113635

But for SEO reasons I need to automatically and invisibly remove the /index.php/ part of the url. Extensive googling and searching of Stack Overflow have only lead me up blind alleys which either completely break the site or leave me at square one.

Httpd.conf sample:

<VirtualHost 109.200.2.197:80>

  <Directory /var/www/sites/ms_dev>
       Options FollowSymLinks ExecCGI
       AllowOverride All
    Options +Indexes
  </Directory>

  <FilesMatch "\.(js|css|html|pdf|jpg|gif)$">
    SetOutputFilter DEFLATE
  </FilesMatch>

  CustomLog /var/log/httpd/ms-dev combined
  ErrorLog /var/log/httpd/errors-ms-dev

  AcceptPathInfo On

  php_value date.timezone Europe/London
  php_value magic_quotes_gpc 0
  php_value magic_quotes_runtime 0


  RewriteEngine On
  RewriteRule ^/awstats - [L]
  RewriteRule ^/hold\.php - [L]
  RewriteRule content/treemenu/? /index_treemenu.php [L]
  RewriteRule ^/images/.* - [L]
  RewriteRule ^/var/storage/.* - [L]
  RewriteRule ^/var/[^/]+/storage/.* - [L]
  RewriteRule ^/var/cache/texttoimage/.* - [L]
  RewriteRule ^/var/[^/]+/cache/texttoimage/.* - [L]
  RewriteRule ^/var/[^/]+/cache/public/.* - [L]
  RewriteRule ^/var/cache/public/javascript/.* - [L]
  RewriteRule ^/design/[^/]+/(stylesheets|images|javascript)/.* - [L]
  RewriteRule ^/share/icons/.* - [L]
  RewriteRule ^/extension/[^/]+/design/[^/]+/(stylesheets|images|lib|flash|javascripts?)/.* - [L]
  RewriteRule ^/packages/styles/.+/(stylesheets|images|javascript)/[^/]+/.* - [L]
  RewriteRule ^/packages/styles/.+/thumbnail/.* - [L]
  RewriteRule ^/favicon\.ico - [L]
  RewriteRule ^/robots\.txt - [L]
  RewriteRule ^/crossdomain\.xml - [L]

  RewriteRule !\.(gif|jpe?g|png|css|s|ico|js|jar|html)|var(.+)storage.pdf(.+)\.pdf$ /index.php

  ServerAdmin test@morningstaronline.co.uk
  DocumentRoot /var/www/sites/ms_dev
  ServerName ms_dev
  ServerAlias dev.morningstaronline.co.uk
  ServerAlias test.morningstaronline.co.uk
  DirectoryIndex index.php

</VirtualHost>

This is based on an old httpd.conf I inherited from our live server which also serves urls with the index.php intact (undesired).

Any help will be greatly appreciated.

2 Answers2

0

It seems that the last line in the recommended RewriteRules is missing :

RewriteRule .* /index.php

Ref : http://doc.ez.no/eZ-Publish/Technical-manual/4.x/Installation/Virtual-host-setup/Virtual-host-example

Nicolas
  • 253
  • 1
  • 7
  • Thank you both for your quick reply, but the problem still remains when using either solution, or indeed both. Entering either http://dev.morningstaronline.co.uk/index.php/content/view/full/113713 or http://dev.morningstaronline.co.uk/content/view/full/113713 both bring up the correct page, but the index.php remains (in the former). Could there be a config option lurking elsewhere on my server that I don't know about? Thanks again – user1269362 Mar 19 '12 at 16:04
  • Have you tried forcing the "ForceVirtualHost" configuration directive to true, in eZ Publish ? You can find more details here : https://github.com/ezsystems/ezpublish/blob/master/settings/site.ini#L659 – Nicolas Mar 21 '12 at 18:55
0

Use this code in your .htaccess:

# to make any index.php/foo to /foo in browser (external redirect)
RewriteRule ^index\.php/(.+)$ $1 [L,NC,R]

# to forward any /foo to /index.php/foo (internal redirect)
RewriteRule ^((?!index\.php).*)$ index.php/$1 [L,NC]
anubhava
  • 761,203
  • 64
  • 569
  • 643