html - 通过网址访问图像,不包含扩展名

标签 html webserver

我以前在网上见过这个,但我无法理解它是如何工作的。希望有人能帮忙解释一下。

假设我们在这个地址有一张照片。 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/

相关文章:

html - .css 或其他文件中的 <css> 标签

jquery - 鼠标悬停使表格单元格发疯

javascript - Owl Carousel 淡入淡出效果无法使用 animate.css

apache - 通过 Apache 的 Tomcat

git - 如何在没有ssh auth的情况下设置git服务器

asp.net - Extensionless MVC 和 IIS 8 请求过滤

根据数据属性查找元素的 jQuery 选择器不起作用

apache - 在托管多个 vhost 条目的单个服务器上避免 SNI for SSL

web-applications - 如何告诉 Hunchentoot 在哪里可以找到要提供的静态网页?

javascript - 获取输入字段数据以保存在选择选项值中