简体   繁体   English

.htaccess - 添加尾部斜杠和内部重定向

[英].htaccess - Add Trailing Slash And Internal Redirect

In my .htaccess file, I'm using the code:在我的 .htaccess 文件中,我使用了以下代码:

RewriteEngine on
RewriteRule ^learn/(.*?)/(.*?)/ /learn.php?lang=$1&topic=$2
RewriteRule ^videos/(.*?)/(.*?)/ /video.php?lang=$1&topic=$2

which works fine.这工作正常。 But it works on http://domain.com/learn/v1 and http://domain.com/learn/v1/ (notice the slash change).但它适用于http://domain.com/learn/v1http://domain.com/learn/v1/ (注意斜线变化)。 I want to redirect the non-slash version to slash version maintaining the internal redirect above.我想将非斜杠版本重定向到斜杠版本,以保持上面的内部重定向。 I tried to add anothe RewriteRule to do that but then it gives me 404.我试图添加另一个 RewriteRule 来做到这一点,但它给了我 404。

Any help would be appreciated.任何帮助,将不胜感激。

Try:尝试:

RewriteEngine on

## Adding a trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule [^/]$ %{REQUEST_URI}/ [L,R=302]

# internal rewrites
RewriteRule ^learn/(.*)/(.*)/$ learn.php?lang=$1&topic=$2 [L,QSA]
RewriteRule ^videos/(.*)/(.*)/$ video.php?lang=$1&topic=$2 [L,QSA]

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

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