使用 .htaccess 在 URL 末尾添加特定文本

问题描述 投票:0回答:1

使用 .htaccess 我想在 URL 末尾添加特定文本。在下面的示例中,我想在用户访问时在 URL 末尾添加单词“Hello”

https://example.com/aboutus/

用户输入的网址:

https://example.com/aboutus/

URL 重写为:

https://example.com/aboutus/Hello

注意:如果用户输入

https://example.com/aboutus/Hello 

URL 应保留

https://example.com/aboutus/Hello

我是 .htaccess 新手

.htaccess
1个回答
0
投票

我使用 .htaccess 已经有一段时间了,但是你可以了:

# Check if your request already containts 'Hello' at the end
RewriteCond %{REQUEST_URI} !/Hello/?$
# Apply the rule for the path "/aboutus" or "/aboutus/"
RewriteRule ^aboutus/?$ /aboutus/Hello [L,R=301]
© www.soinside.com 2019 - 2024. All rights reserved.