1

我正在尝试使用 Apache rewriterules 从 url 中删除 index.php,但我遇到了障碍。

以下 url 当前解析为正确的页面:

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

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

但出于 SEO 原因,我需要自动且不可见地删除 /index.php/ 部分的 url。对 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。

任何帮助将不胜感激。

4

2 回答 2

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]
于 2012-03-18T10:30:59.677 回答
0

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

RewriteRule .* /index.php

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

于 2012-03-18T10:24:20.240 回答