添加尾部斜杠 .htaccess

编程入门 行业动态 更新时间:2024-10-15 08:20:42
本文介绍了添加尾部斜杠 .htaccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试获得以下效果(使用此本地文件 localhost/[company_name]/[project_name]/.htaccess):

I'm trying to get the following effect (using this local file localhost/[company_name]/[project_name]/.htaccess):

localhost/[company_name]/[project_name]/page-1 (adds slash) localhost/[company_name]/[project_name]/page-1/ (does nothing) localhost/[company_name]/[project_name]/page-1/subpage-1 (adds slash) www.example/page-1 (adds slash)<br /> www.example/page-1/ (does nothing) etc.

我想要完成的事情是这个 .htaccess 不再需要路径 localhost/[company_name]/[project_name]/ 这样我就不必每次上传时对其进行编辑.

The thing I want to accomplish is that this .htaccess doesn't need the path localhost/[company_name]/[project_name]/ anymore so that I don't have to edit this each time it's been uploaded.

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

我在这里找到了上面的代码:向 URL 添加尾随斜杠,但它只能动态使用 HOST 并丢弃路径.有人有解决方案来实现这种效果吗?

I found the code above here: Add Trailing Slash to URLs, but it only makes it possible to use the HOST dynamically and discards the path. Does someone a solution to accomplish this effect?

推荐答案

RewriteCond %{REQUEST_URI} !(/$|.) RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]

这个代码需要放在你的.htaccess文件的顶部,下面是RewriteEngine On

This code needs to be put at the top of your .htaccess file below RewriteEngine On

更多推荐

添加尾部斜杠 .htaccess

本文发布于:2023-11-01 13:13:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549415.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:斜杠   尾部   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!