简体   繁体   English

MOD_REWRITE-URL尾随SLASH

[英]MOD_REWRITE - URL ENDING TRAILING SLASH

Options -Indexes +FollowSymLinks -MultiViews
RewriteEngine On

RewriteCond %{HTTP_HOST} ^(.*)$ [NC]
RewriteCond %{HTTP_HOST} !^(.*)\.(.*)\. [NC] 
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ HTTP%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_URI} !(/$|\.) 
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L] 

ServerSignature Off

RewriteRule ^cookie-policy/?$ cookie_policy.php [NC,L]`

Hello I'm struggling really hard with URL closing trailing slash. 您好,我非常努力地在URL末尾添加斜杠。

RewriteRule ^cookie-policy/?$ cookie_policy.php [NC,L]

I would like, for example, to force a redirection from www.website.com/cookie-policy to www.website.com/cookie-policy/ 例如,我想强制从www.website.com/cookie-policy重定向到www.website.com/cookie-policy/

Use this: 用这个:

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

It will add a / to end of your URLs. 它将在您的网址末尾添加一个/ Make sure you clear your cache before testing this. 在测试之前,请确保清除缓存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM