简体   繁体   English

mod_rewrite:删除www和斜杠

[英]mod_rewrite: remove www and trailing slash

I already have a rule set up to remove www from my urls and redirect them... 我已经设置了从我的网址中删除www并将其重定向的规则...

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

*note-I had to put quotes around the percent sign to post this message, the actual rule does not contain them. *注意-我必须在引号前后加上引号,以发布此消息,但实际规则不包含这些引号。

I now want to also strip off any trailing / 我现在也想删除所有尾随/

How would I do this? 我该怎么做?

Add an extra rule: 添加额外的规则:

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

# remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/$ $1 [L,R=301]

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

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