【问题标题】:Rewriting index.php form URL using only httpd.conf on EZ Publish site在 EZ Publish 网站上仅使用 httpd.conf 重写 index.php 表单 URL
【发布时间】:2012-03-31 01:58:53
【问题描述】:

我正在尝试使用 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

但出于 SEO 原因,我需要自动且不可见地删除网址的 /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 的网址(不需要)。

任何帮助将不胜感激。

【问题讨论】:

    标签: apache url mod-rewrite ezpublish


    【解决方案1】:

    建议的 RewriteRules 中的最后一行似乎丢失了:

    RewriteRule .* /index.php
    

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

    【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-15
      • 1970-01-01
      • 2012-05-22
      • 2017-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多