简体   繁体   English

重定向.html和.php链接至无扩展名

[英]Redirect .html and .php links to no extensions

I have a website , that i wrote by hand, no CMS, just for learning purposes. 我有一个用手写的网站 ,没有CMS,仅用于学习目的。 A while ago I rewrote my website using more of php and renamed the .html files to .php . 不久前,我使用更多的php重写了我的网站,并将.html文件重命名为.php

Ages ago I edited the .htaccess added some code that i got online. 多年以前,我编辑.htaccess添加了一些我在线上的代码。 And what it did was, it doesn't use a tutorials/article.html or tutorials/article.php but no extensions at all: tutorials/article 它所做的是,它不使用tutorials/article.htmltutorials/article.php但完全不使用扩展名: tutorials/article

I found that allot of websites that linked to my articles are still using the .html extension. 我发现链接到我的文章的网站分配仍在使用.html扩展名。

My question is how do I redirect all the links going to .php and .html to no extensions at all? 我的问题是如何将所有指向.php.html的链接重定向到完全没有扩展名?

Also: I have social haring buttons on my website, does the redirect to no extensions at all, mean that all the +1 , likes , tweets and linkedin are no more? 另外:我的网站上有社交标签按钮,重定向到所有扩展程序都不会,是否意味着所有+1 ,顶, likestweets和linkedin都消失了?

Add the following to your htaccess. 将以下内容添加到您的htaccess中。 It will remove the .html 它将删除.html

RewriteRule ^([^\.]+)$ $1.html [NC,L] 

Source: http://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/ 来源: http//alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/

Do this with htaccess htaccess做到这一点

Something like below, for both url with .php & html extention 如下所示,对于带有.phphtml扩展名的网址

RewriteCond %{THE_REQUEST} \ /+([^\?\ ]+)\.(php|html?)
RewriteRule ^ /%1 [L,R=301]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM