开发者

Redirect to trailng slash (htaccess)

开发者 https://www.devze.com 2023-04-02 05:12 出处:网络
Trying to add trailing slash to every link. i.e. http://mysite.com/products should make 301 redirect to http://mysite.com/products/ etc. But how? Here is htaccess:

Trying to add trailing slash to every link. i.e. http://mysite.com/products should make 301 redirect to http://mysite.com/products/ etc. But how? Here is 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/开发者_C百科js_compactor.php?filename=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php
RewriteRule /admin/(.*)$ /admin/index.php

Need help!


Here's what I'm using

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]

Basically, this makes sure that it doesn't add a trailing to file and only folders or paths.

EDIT

To make it domain independent

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

精彩评论

暂无评论...
验证码 换一张
取 消