【发布时间】:2011-03-06 09:44:25
【问题描述】:
我有一个网站,所有页面都是 php 脚本,所以 URL 以 .php 结尾。
我已将以下内容添加到 .htaccess 文件中,现在我可以访问没有 .php 扩展名的 .php 文件:
RewriteEngine On # Turn on rewriting
RewriteCond %{REQUEST_FILENAME}.php -f # If the requested file with .php on the end exists
RewriteRule ^(.*)$ $1.php # serve the PHP file
到目前为止一切顺利。但现在我想在所有 .php 文件上添加一个重定向,以便我无法控制的任何旧链接都被重定向到新版本的 URL。
我试过了:
RewriteEngine On # Turn on rewriting
RewriteCond %{REQUEST_URI} .*\.php
RewriteRule ^(.*)\.php$ http://example.com/$1 [R=permanent,L]
RewriteCond %{REQUEST_FILENAME}.php -f # If the requested file with .php on the end exists
RewriteRule ^(.*)$ $1.php [L] # serve the PHP file
但即使对于不以 .php 结尾的 URL,这似乎也会发送重定向,因此我陷入了无限循环。我尝试的任何其他组合似乎都不匹配任何请求(并将我留在 page.php)或所有请求(并让我陷入循环)。
【问题讨论】:
标签: php apache mod-rewrite seo