重定向结尾以.php没有扩展名的所有网址 [英] Redirecting all URLs that end in .php to no extension

查看:267
本文介绍了重定向结尾以.php没有扩展名的所有网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近删除了的.php 扩展名从我的所有网页。

谷歌的结果仍显示:

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

这些都是现在死链接。新的是:

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

什么是适当的重定向,这样,如果有人点击.php为URL之一,他们将被重定向到无扩展名的URL

解决方案
  1. 使用<链接REL =规范的href =FULL_PROPER_URL/> 在网页中。这将告诉搜索引擎显示搜索结果时使用的网址,看到重复的网址时,会将此作为主要网址。详情请看这里:

    • <一个href="http://www.google.com/support/webmasters/bin/answer.py?answer=139394">http://www.google.com/support/webmasters/bin/answer.py?answer=139394
    • <一个href="http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html">http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html
  2. 使用301永久重定向。请注意,这不会阻止谷歌或其他搜索引擎请求的.php 如果这样的链接是公开的一些其他网站的页面。

这需要放置在.htaccess文件中的网站根目录。如果放在其他地方的一些调整是必须的。

 选项+了FollowSymLinks -MultiViews
RewriteEngine叙述上
的RewriteBase /

#重定向到.PHP少链接,如果直接请求
的RewriteCond%{THE_REQUEST} ^ [AZ] + \ S + \ PHP \ SHTTP /.+
重写规则^(。+)\。PHP $ 1 [R = 301,L]
 

以上规则会做301重定向到一个PHP少URL。如果直接请求PHP文件它只会重定向,并不会触及已经重写的URL。

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

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

  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.

这篇关于重定向结尾以.php没有扩展名的所有网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆