URL重写字

发布于 2024-12-23 15:30:28 字数 635 浏览 1 评论 0原文

我有一个相当简单的问题,我无法弄清楚。

这是我的 .htaccess 规则:

RewriteRule ^articles/([a-zA-Z0-9_-]+)/?$ articles.php?article=$1

这会产生 URL,例如 www.example.com/articles/article-name 我想要的是将规则中的“文章”更改为当前 URL 的名称。

例如来自:

www.example.com/articles/article-name

至:

www.example.com/blog/article-name
www.example.com/gallery/article-name

我目前正在编写链接为:

<a href="articles/$articleName">

我已将其更改为以下内容,但无法让 .htaccess 使用它:

<a href="$pageNoExtension/$articleName">

提前致谢,新年快乐!

I have a fairly simple problem which I can't figure out.

Here is my .htaccess rule:

RewriteRule ^articles/([a-zA-Z0-9_-]+)/?$ articles.php?article=$1

This results in URL's such as www.example.com/articles/article-name
What I'd like is to change the 'articles' in the rule, to the name of the current URL.

For example from:

www.example.com/articles/article-name

To:

www.example.com/blog/article-name
www.example.com/gallery/article-name

I am currently writing links as:

<a href="articles/$articleName">

I have changed it to the following, but can't get the .htaccess working with it:

<a href="$pageNoExtension/$articleName">

Thanks in advance and happy new year!

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

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

发布评论

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

评论(1

眼眸里的那抹悲凉 2024-12-30 15:30:28
RewriteRule ^([A-Za-z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ $1.php?article=$2

也祝你新年快乐:)

RewriteRule ^([A-Za-z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ $1.php?article=$2

Happy new year to you too :)

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