问题描述
我找到了这个问题的很多答案(并且我已经阅读了许多答案),但是它们都是关于带有模式和类似内容的更高级的内容。
我只需要一个非常简单和基本的静态URL重定向。
如果我在网址中添加斜杠,则重定向将不起作用,我只是想不通为什么。
示例:
I find a lot of answers to this question (and I have read dozens of them), but they are all about more advanced stuff with patterns and such stuff.I just need a very simple and basic redirect for static urls.If I add a trailing slash to the url, the redirect doesn't work and I just can't figure out why.Example:
RewriteEngine On
Redirect 301 /content https://www.example.com/site/content.html
Redirect 301 /content/ https://www.example.com/site/content.html
https://example.com/content
确实有效, https://example.com/content/
重定向到 https://example.com/site/
https://example.com/content
does work, https://example.com/content/
redirects to https://example.com/site/
问题是什么
推荐答案
不要将 mid_rewrite
规则与<$ c混合使用$ c>重定向(mod_alias)。在您的根.htaccess中将此规则用作第一条规则:
Don't mix mid_rewrite
rules with Redirect
(mod_alias). Use this rule as very first rule in your root .htaccess:
RewriteEngine On
RewriteRule ^content/?$ https://www.example.com/site/content.html [L,NC,R=302]
这篇关于htaccess简单重定向不适用于斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!