开发者

Redirecting all URLs that end in .php to no extension

I've recently removed the .php extension from all of my pages.

Google results are still showing:

www.mysite.com/page.php
www.mysite.com/directory/page-example.php

Thes开发者_运维技巧e are now dead links. The new ones are:

www.mysite.com/page
www.mysite.com/directory/page-example

What would be the appropriate redirect so that if someone clicks one of the .php URLs, they are redirected to the extension-less URL


  1. Use <link rel="canonical" href="FULL_PROPER_URL" /> in your web pages. This will tell Search Engine to use that URL when displaying search results and will treat this a s main URL when seeing duplicate URLs. Details are here:

    • http://www.google.com/support/webmasters/bin/answer.py?answer=139394
    • http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html
  2. Use 301 Permanent Redirect. Please note that this WILL NOT stop Google or any other search engine to requesting .php pages if such link is publicly available on some other site.

This needs to be placed in .htaccess file in website root folder. If placed elsewhere some tweaking may be required.

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

# redirect to .php-less link if requested directly
RewriteCond %{THE_REQUEST} ^[A-Z]+\s.+\.php\sHTTP/.+
RewriteRule ^(.+)\.php $1 [R=301,L]

The above rule will do 301 redirect to a php-less URL. It will only redirect if .php file was requested directly and will not touch already rewritten URLs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜