htaccess 不重定向

发布于 2024-10-22 05:25:16 字数 514 浏览 1 评论 0原文

我有

www.mydomain.com/page_articles

一些链接,

www.mydomain.com/page_articles/some_article

但“some_article”是从php文件“load.php”渲染的,所以它看起来像:

www.mydomain.com/page_articles/load.php?page=some_article

我会在htaccess中放入什么,以便我可以拥有漂亮的链接?

我目前有:

RewriteEngine On
RewriteRule ^page_articles$ /page_articles/load.php?page=$1
RewriteRule ^page_articles/$ page_articles/load.php?page=$1

谢谢

i have

www.mydomain.com/page_articles

with links that would point to

www.mydomain.com/page_articles/some_article

but "some_article" get rendered from a php file "load.php" so it would look like:

www.mydomain.com/page_articles/load.php?page=some_article

What would i put in htaccess so that i can have pretty links?

I currently have:

RewriteEngine On
RewriteRule ^page_articles$ /page_articles/load.php?page=$1
RewriteRule ^page_articles/$ page_articles/load.php?page=$1

THanks

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

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

发布评论

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

评论(2

满意归宿 2024-10-29 05:25:16
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^page_articles/(.*)$ page_articles/load.php?page=$1
</IfModule>

在字符串中添加括号允许您在页面变量 $1 中使用“some _articles”,这是假设 page_articles 文件夹中有一个名为 load.php 的文件

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^page_articles/(.*)$ page_articles/load.php?page=$1
</IfModule>

Adding the brackets in the string allows you to use "some _articles" it the page variable $1, this is assuming there is a file called load.php in the page_articles folder

梓梦 2024-10-29 05:25:16

类似的事情应该有效。 (.) 将 / 之后的所有内容捕获到 $1 中。 . = 任意字符 0 次或多次。 RewriteCond 告诉 RewriteRule 如果匹配以 load.php 开头则忽略它(以避免无限循环)。问号表示可能有也可能没有尾随 /。

RewriteCond $1 !^load\.php
RewriteRule ^page_articles/?(.*) /page_articles/load.php?page=$1 [T=application/x-httpd-php,L,NC]

Something along the lines of this should work. The (.) captures whatever comes after the / into $1. . = any character 0 or more times. The RewriteCond is telling the RewriteRule ignore it if it the match starts with load.php (to avoid an infinite loop). The question mark indicates that there may or may not be a trailing /.

RewriteCond $1 !^load\.php
RewriteRule ^page_articles/?(.*) /page_articles/load.php?page=$1 [T=application/x-httpd-php,L,NC]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文