.htaccess - 重定向到尾部斜杠 (htaccess)

标签 .htaccess apache2

尝试为每个链接添加尾部斜杠。即http://mysite.com/products应该使 301 重定向到 http://mysite.com/products/等等,但是如何呢?这是 htaccess:

RewriteEngine on
DirectoryIndex index.php
Options -Indexes
RewriteBase /

RewriteCond %{REQUEST_URI} \.css$
RewriteCond %{QUERY_STRING} ^pack$
RewriteRule ^(.*)$ /modules/system/css_compactor.php?filename=$1 [L]
RewriteCond %{REQUEST_URI} \.js$
RewriteCond %{QUERY_STRING} ^pack$
RewriteRule ^(.*)$ /modules/system/js_compactor.php?filename=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php
RewriteRule /admin/(.*)$ /admin/index.php

需要帮助!

最佳答案

这是我正在使用的

RewriteEngine on
RewriteBase /

### CHECK FOR TRAILING SLASH - Will ignore files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://example.com/$1/ [L,R=301]

基本上,这可以确保它不会向文件添加尾随,而仅向文件夹或路径添加尾随。

编辑

使其独立于域

RewriteRule ^(.*)$ $1/ [L,R=301]

关于.htaccess - 重定向到尾部斜杠 (htaccess),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7267755/

相关文章:

apache - 无法在 apache2 中启用 .htaccess

.htaccess - 通过在 .htaccess 中启用 gzip 来提高 magento 速度

CSS 不工作?

php - 访问本地主机的 Apache 2 问题

.htaccess - 临时重定向到维护页面

.htaccess - 如果文件不存在则重定向到 root

php - Laravel 应用程序未在 xampp 或实时服务器上运行,但在 php artisan 服务上运行良好

php - .htaccess 重定向错误和循环

php - http :keep-alive keep the php resources open or does it free all the resources? 吗

shell - 错误 : site default-ssl not properly enabled