在目录末尾添加斜杠 +更多(htaccess)

发布于 2024-08-23 09:12:44 字数 710 浏览 3 评论 0原文

这超出了我的水平,我需要一些帮助。

在 htaccess 中为以下内容制定重定向规则...

  1. 如果 example.com/1stleveldirectory 不以斜杠结尾,请添加一个。
  2. 如果 example.com/1stleveldirectory/ 以斜杠结尾,则不要添加任何内容。
  3. 如果 example.com/1stleveldirectory/file 像这样添加 .html。
  4. 如果 example.com/1stleveldirectory/file.html 是这样的,则不要添加任何内容。

没有超过第一级的可公开访问的目录

谢谢!

编辑:我应该说我已经在文件顶部有这个代码。

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.([^.]+.[^.]+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

Options +FollowSymLinks
RewriteRule ^([^/]*)/([^/]*)\.html$ /index.php?cat=$1&name=$2 [L]
RewriteRule ^([^/]*)/$ /index.php?cat=$1 [L]

This is beyond my level and I need some help.

In the htaccess make redirect rules for the following...

  1. if example.com/1stleveldirectory doesn't end in a slash add one.
  2. if example.com/1stleveldirectory/ ends in a slash don't add anything.
  3. if example.com/1stleveldirectory/file is like this add .html.
  4. if example.com/1stleveldirectory/file.html is like this don't add anything.

There are no publicly accessible directories past the first level

Thanks!

EDIT: I should have said I already have this code at the top of the file.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.([^.]+.[^.]+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

Options +FollowSymLinks
RewriteRule ^([^/]*)/([^/]*)\.html$ /index.php?cat=$1&name=$2 [L]
RewriteRule ^([^/]*)/$ /index.php?cat=$1 [L]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

成熟的代价 2024-08-30 09:12:44

尝试这些规则:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^[^/]+$ %{REQUEST_URI}/ [L,R=301]
RewriteCond $0 !.+\.html$
RewriteRule ^[^/]+/[^/]+$ %{REQUEST_URI}.html [L,R=301]

Try these rules:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^[^/]+$ %{REQUEST_URI}/ [L,R=301]
RewriteCond $0 !.+\.html$
RewriteRule ^[^/]+/[^/]+$ %{REQUEST_URI}.html [L,R=301]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文