重定向与HTML扩展名的文件,以文件不带扩展名(以URL) [英] redirecting files with html extension to files without extension (in url)

查看:174
本文介绍了重定向与HTML扩展名的文件,以文件不带扩展名(以URL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近更换了使用htaccess的,这样我的网址将不显示文件扩展名我的网站的网址。现在我的问题是,我已经创建了一个新的XML网站地图,使我的网址将扩展名!在谷歌网站管理员工具告诉我关于重复内容的问题! IE浏览器。页面和page.html即可拥有相同的标题....所以我的问题是如何重定向文件扩展HTML的网址URL以进行扩展! 这是我的网站的网址与HTML扩展的例子

I have recently changed my website url using htaccess so that my urls will not show file extensions. Now my problem is as I have created a new xml sitemap so that my url will be extensionless!!! the Google webmaster tool is telling me about duplicate content issue!! ie. page and page.html have same title.... so my question is how do i redirect the urls with file extension html to urls with out extension!!! this is an example of my website url with html extension

http://www.shenazhpeyk.co.uk/coding-machines.html

我想重定向,并更改为

http://www.shenazhpeyk.co.uk/coding-machines

这样就解决了问题,谷歌网站管理员工具(请提供我的htaccess文件中的$ C $下使用)

so that will fix the issue with Google webmaster tools (Please provide me a code for use in htaccess file)

非常感谢

推荐答案

发现这个code为好。不知道是否会完成同样的事情。似乎为我工作一样以上(对于PHP)的人。

Found this code as well. Not sure if it will accomplish the same thing. Seems to work for me as does the one above (for PHP).

RewriteEngine On

# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ /$1 [R=301,L]

# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ /$1 [R=301,L]

# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]

我想知道有关尾随斜线,或是否应该存在或省略?

I am wondering about the trailing slashes and whether those should be there or omitted?

这篇关于重定向与HTML扩展名的文件,以文件不带扩展名(以URL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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