简体   繁体   English

在重写htaccess中强制尾随斜杠

[英]Force trailing slashes in rewrite htaccess

My htaccess 我的htaccess

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/(.*)$ /sentence-examples/examplesentence.php?havethis=$1&word=$2 [L]

The results URL is /sentence-examples/acco-acti/accolading/ 结果网址是/ sentence-examples / acco-acti / accolading /

If I remove the last slash /sentence-examples/acco-acti/accolading still works fine 如果我删除最后一个斜杠/ sentence-examples / acco-acti / accolading仍然可以正常工作

If I remove the third slash /sentence-examples/acco-acti <- 404's 如果我删除第三个斜杠/ sentence-examples / acco-acti <-404

Is there a way to force the slash so even if a user types the url without a slash it will change it to slash? 有没有一种方法可以强制使用斜杠,因此即使用户键入不带斜杠的url也会将其更改为斜杠?

The problem with trailing slashes is they can modify the queries. 斜杠的问题在于它们可以修改查询。 For example: 例如:

 http://mysite.com/index.php?par=this_query
 // is differente from
 http://mysite.com/index.php?par=this_query/

In the last case, the $_GET value has a trailing slash, which usually leads to error. 在最后一种情况下,$ _GET值带有斜线,通常会导致错误。

So yes, there are ways to force trailing slashes in .htacces files, but it is not a good idea. 因此,是的,有多种方法可以在.htacces文件中强制使用尾部斜杠,但这不是一个好主意。 It's already hard to figure out how to remove them in certain cases, why creating more. 已经很难弄清楚在某些情况下如何删除它们,为什么还要创建更多。

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

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