【问题标题】:insert back slash at the end of the url htaccess在 url htaccess 的末尾插入反斜杠
【发布时间】:2012-08-08 17:34:21
【问题描述】:

我正在做一个关于 php 的项目。动态 url 将更改为搜索引擎友好的 url。我正在创建 htaccess 文件以重写 url。我不熟悉 .htaccess。我正在尝试将 bakslash 插入到 url。 如果网址不以“/”或“.html”结尾,则在最后添加反斜杠。请帮助检查以“/”或“.html

现在我正在尝试这段代码

 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_URI} !\..+$
 RewriteCond %{REQUEST_URI} !/$
 RewriteRule (.*) http://www.example.com/$1/ [R=301,L] 

此代码仅在 http://www.example.com/hh 情况下插入黑色斜线。但我会尝试在任何文档根目录中添加反斜杠

例如

http://www.example.com/hh/yyy   - http://www.example.com/hh/yyy/
http://www.example.com/h        - http://www.example.com/h/

【问题讨论】:

标签: php apache .htaccess url url-rewriting


【解决方案1】:

尝试以下方法:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/(.*[^/]+)$ http://www.example.com/$1/ [R=301,L] 

【讨论】:

  • 这仅适用于 http: //www.example.com/hdd 情况,它不会重定向 http://www.example.com/hdd/ hh .
猜你喜欢
  • 1970-01-01
  • 2021-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-13
  • 2012-10-27
  • 1970-01-01
相关资源
最近更新 更多