我以前在网上见过这个,但我无法理解它是如何工作的。希望有人能帮忙解释一下。
假设我们在这个地址有一张照片。 http://www.website.com/image-150x150.jpg
如果您转到http://www.website.com/image-150x150,我该如何设置它?它显示了那张图片?
所以唯一的区别是我不必包含扩展名,即。 *.jpg。
除此之外,我还希望能够像这样引用它:
<img src="http://www.website.com/image-150x150" />
最佳答案
如果您使用 Apache,则需要添加与此类似的 .htaccess
规则:
RewriteEngine On
redirectMatch 301 ^(.*)\.jpg $1
对于 IIS(我根本没有使用过!),请考虑使用如下内容:
<rewrite>
<rules>
<rule name="rewrite php">
<!--Removes the .php extension for all pages.-->
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" negate="true" pattern="(.*).jpg" />
</conditions>
<action type="Rewrite" url="{R:1}.jpg" />
</rule>
</rules>
</rewrite>
我确信您必须根据您的需要更改此设置。
关于html - 通过网址访问图像,不包含扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15796375/