douyan1972 2017-02-09 06:01
浏览 83
已采纳

如何使用HTACCESS将特定.html替换为尾部斜杠

I have this command in .htaccess

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html

And this command remove the .html at the end this looks ok but how can I add at the end? Because if I try this code:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html

RewriteCond %{REQUEST_URI}  !\.(php|html?|jpg|gif)$
RewriteRule ^(.*)([^/])$ http://%{HTTP_HOST}/$1$2/ [L,R=301]

The .html is there again. I want to replace the .html into a trailing slash. And also I want to do this in 1 HTML file only. So my URL is like this for now.

http://mysamplesite.com/project.html/
  • 写回答

3条回答 默认 最新

  • dongyi6845 2017-02-09 06:25
    关注

    You can use it like this:

    RewriteEngine on
    
    RewriteCond %{THE_REQUEST} \s/+project\.html\s [NC]
    RewriteRule ^ http://%{HTTP_HOST}/%{REQUEST_URI}/ [NC,L,R=301,NE]
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.html -f
    RewriteRule ^(.+?)/?$ $1.html [L]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 Odoo17操作下面代码的模块时出现没有'读取'来访问
  • ¥50 .net core 并发调用接口问题
  • ¥15 网上各种方法试过了,pip还是无法使用
  • ¥15 用verilog实现tanh函数和softplus函数
  • ¥15 Hadoop集群部署启动Hadoop时碰到问题
  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 QTableWidget重绘程序崩溃
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题