仅使用EZ Publish站点上的httpd.conf重写index.php表单URL

时间:2012-03-14 15:25:51

标签: apache url mod-rewrite ezpublish

我正在尝试使用Apache rewriterules从url中剥离index.php,但我遇到了一堵砖墙。

以下网址目前已解析为正确的网页:

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

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

但出于搜索引擎优化的原因,我需要自动无形地删除网址的/index.php/部分。广泛的谷歌搜索和搜索Stack Overflow只会导致盲目的小巷,要么完全破坏网站,要么让我留在第一方。

Httpd.conf示例:

<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>

这是基于我从我们的实时服务器继承的旧httpd.conf,它还提供index.php完整(不受欢迎)的URL。

非常感谢任何帮助。

2 个答案:

答案 0 :(得分:0)

似乎缺少推荐的RewriteRules中的最后一行:

RewriteRule .* /index.php

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

答案 1 :(得分:0)

在.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]