重写规则问题

发布于 2024-09-01 20:31:40 字数 249 浏览 5 评论 0原文

有什么方法可以使用 RewriteRule 显示这些链接:

/articles_history.php

/articles_geography.php

as

/articles/history.html

/articles/geography.html

我在根目录上创建了一个 .htacesss 文件,想知道是否通过在 .htaccess 文件中放置某种代码可以实现上述目的。

Is there any way i can use RewriteRule to show these links:

/articles_history.php

/articles_geography.php

as

/articles/history.html

/articles/geography.html

I created a .htacesss file on my root directory and would like to know if the above is possible by placing some kind of code in the .htaccess file.

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

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

发布评论

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

评论(3

夏日落 2024-09-08 20:31:40
RewriteEngine On
RewriteRule /articles/(.+)\.html /articles_$1.php [L,QSA]
RewriteEngine On
RewriteRule /articles/(.+)\.html /articles_$1.php [L,QSA]
鸠书 2024-09-08 20:31:40

是的。

请参阅 http://httpd.apache.org/docs/2.2/mod/mod_rewrite .html

除了RewriteRule之外,您通常还需要通过RewriteEngine指令打开重写引擎。

Yes it is.

See http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html

In addition to RewriteRule, you also need to usually turn the rewrite engine on by the RewriteEngine directive.

指尖微凉心微凉 2024-09-08 20:31:40

在您的 .htaccess 中尝试一下:

RewriteEngine on
RewriteRule ^article/([^/]+)\.html$ articles_$1.php [L]

对于任意输入:

RewriteEngine on
RewriteRule ^([^/]+)/([^/]+)\.html$ $1_$2.php [L]

Try this in your .htaccess:

RewriteEngine on
RewriteRule ^article/([^/]+)\.html$ articles_$1.php [L]

And for an arbitrary input:

RewriteEngine on
RewriteRule ^([^/]+)/([^/]+)\.html$ $1_$2.php [L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文