需要 RewriteRule 方面的帮助 - Apache

发布于 2024-09-04 08:22:28 字数 406 浏览 3 评论 0原文

这就是我想要做的:

http://www.mysite.com/      >    http://www.mysite.com/index.php
http://www.mysite.com/asd   >    http://www.mysite.com/index.php?page=$1

asd 将是附加到 index.php 的 $page 变量的页面的名称。

我当前的重写规则成功重定向了请求的页面,但无法加载默认的index.php页面。

RewriteEngine On
RewriteRule ^([\w]*)$ /index.php?page=$1 [L]

我该如何解决这个问题? :/

Here's what I want to do:

http://www.mysite.com/      >    http://www.mysite.com/index.php
http://www.mysite.com/asd   >    http://www.mysite.com/index.php?page=$1

asd will be the name of the page(s) that get appended to index.php's $page variable.

My current rewrite rule successfully redirects the requested page but fails to load the default index.php page.

RewriteEngine On
RewriteRule ^([\w]*)$ /index.php?page=$1 [L]

How do I fix this? :/

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

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

发布评论

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

评论(2

眼中杀气 2024-09-11 08:22:28

您需要有一个仅匹配 /: 的规则

RewriteRule ^/$ /index.php [L]

,然后是另一条规则:

RewriteRule ^/([\w]+)$ /index.php?page=$1 [L]

You would need to have one rule that matches just the /:

RewriteRule ^/$ /index.php [L]

And then your other one:

RewriteRule ^/([\w]+)$ /index.php?page=$1 [L]
高速公鹿 2024-09-11 08:22:28

对于我的,我只是将整个路径传递到索引页。

RewriteRule ^.*$ /index.php?page=$0 [L,QSA]

然后使用 list()explode() 将其分块。

list( $param1, $param2, $param3 ) = explode( "/", $_GET['page'] );

否则,您将需要两条规则。

或者使用相同的规则并在 / 页面上有一个空的 ?page= 参数。

For mine, i simply pass the entire path to the index page.

RewriteRule ^.*$ /index.php?page=$0 [L,QSA]

Then use list() and explode() to chunk it up.

list( $param1, $param2, $param3 ) = explode( "/", $_GET['page'] );

Otherwise, you're going to need two rules.

Or use the same rule and on the / page have an empty ?page= parameter.

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