的.htaccess带或不带斜杠 [英] .htaccess with or without slash

查看:321
本文介绍了的.htaccess带或不带斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么我需要做下面的重写规则,使其所以它的工作原理是否不是自己是一个斜线网址的结尾?

IE浏览器。 http://mydomain.com/content/featured 要么 http://mydomain.com/content/featured/

 重写规则^含量/功能/ /content/today.html
 

解决方案

使用了 $ 标记字符串的结束和标记的preceding EX pression被重复零次或一次:

 重写规则^含量/功能/?$内容/ today.html
 

不过,我建议你坚持一个符号,纠正拼写错误:

 #删除尾随斜线
重写规则(。*)/ $ $ 1 [L,R = 301]

#添加结尾的斜杠
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{} REQUEST_FILENAME!-f
重写规则。* [^ /] $ $ 0 / [L,R = 301]
 

What do I need to do to the following rewrite rule to make it so it works whether or not their is a slash at the end of the URL?

ie. http://mydomain.com/content/featured or http://mydomain.com/content/featured/

RewriteRule ^content/featured/ /content/today.html

解决方案

Use the $ to mark the end of the string and the ? to mark the preceding expression to be repeated zero or one times:

RewriteRule ^content/featured/?$ content/today.html

But I recommend you to stick to one notation and correct misspelled:

# remove trailing slashes
RewriteRule (.*)/$ $1 [L,R=301]

# add trailing slashes
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .*[^/]$ $0/ [L,R=301]

这篇关于的.htaccess带或不带斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆