如何链接到没有.html扩展名的页面? [英] How to link to pages without the .html extension?

查看:158
本文介绍了如何链接到没有.html扩展名的页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想链接到我网站内的页面,例如:
不是:mywebsite.com/about.html但是:mywebsite.com/about /



我见过各种网站这样做,但它看起来像他们也反应不同的东西:



Apple.com:
apple.com/iphone/作品,apple.com/iphone/index.html作品,apple.com/iphone重定向。



Opera.com:
opera.com/mobile/ redirects ,opera.com/mobile works,opera.com/mobile.html不会


$ b Mozilla.com:
mozilla .org / en-US / works,mozilla.org/en-US重定向,mozilla.org/en-US/index.html不 工作。



这导致了另一个问题:是否有不同的方法?

编辑:
看起来Apple为每个页面使用一个文件夹,例如一个名为'iphone'的文件夹,里面有一个index.html文件?
但是Opera和Mozilla在.htaccess文件中使用了一些东西?

解决方案

删除扩展



要将.php扩展名从PHP文件(例如yoursite.com/wallpaper.php)中移除到yoursite.com/wallpaper,您必须在.htaccess文件中添加以下代码:

  RewriteEngine On 
RewriteCond%{REQUEST_FILENAME}!-f
RewriteRule ^([^ \。] +)$ $ 1.php [NC,L]

如果您想从html文件中移除.html扩展名例如yoursite.com/wallpaper.html to yoursite.com/wallpaper,您只需修改上面代码的最后一行以匹配文件名即可:

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

就是这样!您现在可以链接HTML文档中的页面,而无需添加页面的扩展名。例如:

 < a href =http://whatever.com/wallpapertitle =wallpaper>壁纸< / A> 


I would like to link to pages inside my website, e.g: Not: mywebsite.com/about.html But: mywebsite.com/about/

I've seen various websites doing this but it looks like they also react differently to things:

Apple.com: apple.com/iphone/ works, apple.com/iphone/index.html works, apple.com/iphone redirects.

Opera.com: opera.com/mobile/ redirects, opera.com/mobile works, opera.com/mobile.html does not work.

Mozilla.com: mozilla.org/en-US/ works, mozilla.org/en-US redirects, mozilla.org/en-US/index.html does not work.

Which leads to another question: Are there different methods for this?

Edit: It seems that Apple uses a folder for every page, e.g. a folder called 'iphone' with an index.html file inside it? But Opera and Mozilla use something in the .htaccess file?

解决方案

Removing Extensions

To remove the .php extension from a PHP file for example yoursite.com/wallpaper.php to yoursite.com/wallpaper you have to add the following code inside the .htaccess file:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

If you want to remove the .html extension from a html file for example yoursite.com/wallpaper.html to yoursite.com/wallpaper you simply have to alter the last line from the code above to match the filename:

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

That’s it! You can now link pages inside the HTML document without needing to add the extension of the page. For example:

 <a href="http://whatever.com/wallpaper" title="wallpaper">wallpaper</a>

这篇关于如何链接到没有.html扩展名的页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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