如何将每个博客的前缀都带有“ new-”使用htaccess

发布于 2025-02-10 23:43:55 字数 161 浏览 1 评论 0原文

我想在每个博客URL slug中添加“新”。

例如,如果某人访问https://www.example.com/blog/post-one它将重定向到https://www.example.com/blog/new-post - 一个

I want to add "new" to every blog URL slug.

For example, if someone visits https://www.example.com/blog/post-one it will redirect to https://www.example.com/blog/new-post-one.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

別甾虛僞 2025-02-17 23:43:55

在root .htaccess文件的顶部,使用mod_rewrite尝试以下内容:

RewriteEngine On

# Redirect "/blog/<post-title>" to "/blog/new-<post-title>"
RewriteRule ^(blog)/(?!new-)([\w-]+)$ /$1/new-$2 [R=302,L]

假设&lt; post-title&gt;仅由字符az组成,az0-9_(underscore)和-(杂种)

(?!) new - ) - 这是否定的lookahead ,它断言&lt; post-title&gt;尚未以new - 。否则,我们将获得无尽的重定向循环。

您无需重复RewriteEngine指令是否已经在文件中(以后)中发生。

At the top of the root .htaccess file try the following using mod_rewrite:

RewriteEngine On

# Redirect "/blog/<post-title>" to "/blog/new-<post-title>"
RewriteRule ^(blog)/(?!new-)([\w-]+)$ /$1/new-$2 [R=302,L]

This assumes <post-title> consists of only the characters a-z, A-Z, 0-9, _ (underscore) and - (hyphen)

(?!new-) - this is a negative lookahead that asserts that the <post-title> does not already start with new-. Otherwise we would get an endless redirect loop.

You do not need to repeat the RewriteEngine directive if it already occurs (later) in the file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文