【问题标题】:How to add more than one file extension to extensionless urls如何向无扩展名网址添加多个文件扩展名
【发布时间】:2017-11-18 16:25:40
【问题描述】:

我已经有适用于 html 的无扩展名 url,但该网站多年前曾经有 php 和 aspx 文件,这些文件也显示为 404。有人可以告诉我在哪里添加 php 和 aspx 到以下内容:

RewriteCond %{THE_REQUEST} \.html
RewriteRule ^(.+)\.html$ http://example.com/$1 [R=301,L]

【问题讨论】:

  • 原来的网址是:http://example.com/about.php,而新的网址是http://example.com/about?要删除 php 和 aspx 扩展,您可以将正则表达式更改为:^(.+)\.(html|php|aspx)$.

标签: php asp.net .htaccess url


【解决方案1】:

您需要将这些扩展添加到 RewriteCond 和 RewriteRule 的模式中:

RewriteCond %{THE_REQUEST} \.(html|php|aspx)
RewriteRule ^(.+)\.(html|php|aspx)$ http://example.com/$1 [R=301,L]

【讨论】:

  • 抱歉没用,内部服务器错误。我假设管道字符的每一侧都有一个空格。是吗?
【解决方案2】:

由于某种原因,当我复制上面的代码时,它在管道字符周围添加了空格。我去掉了空格,然后它就起作用了。

RewriteCond %{THE_REQUEST} \.(html|php|aspx)
RewriteRule ^(.+)\.(html|php|aspx)$ http://example.com/$1 [R=301,L]

谢谢。

【讨论】:

    猜你喜欢
    • 2014-09-06
    • 2012-12-24
    • 1970-01-01
    • 2018-01-14
    • 1970-01-01
    • 2011-11-04
    • 2014-03-07
    • 1970-01-01
    • 2015-07-02
    相关资源
    最近更新 更多