CakePHP 和 .htaccess:如何使用查询字符串重定向 url

发布于 2024-09-28 11:47:48 字数 427 浏览 0 评论 0原文

我想将此网址从 /main.php?page=pages&id=gettingpaidfortakeingsurveys 重定向到 /main/pages/getting-paid-for-takeing-surveys。

谢谢!

[UDPATE]

我在现有的 cakephp .htaccess 上测试了它,但它不起作用。

<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteRule ^/main.php?page=(.+)&id=(.+) /main/$1/$2 [NC]
 RewriteRule ^$ app/webroot/    [L]
 RewriteRule (.*) app/webroot/$1 [L]
</IfModule>

I wanted to redirect this url from /main.php?page=pages&id=gettingpaidfortakingsurveys to /main/pages/getting-paid-for-taking-surveys.

Thanks!

[UDPATE]

i tested it on my existing cakephp .htaccess and it didn't work.

<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteRule ^/main.php?page=(.+)&id=(.+) /main/$1/$2 [NC]
 RewriteRule ^$ app/webroot/    [L]
 RewriteRule (.*) app/webroot/$1 [L]
</IfModule>

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

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

发布评论

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

评论(2

浅听莫相离 2024-10-05 11:47:48

由于您似乎想要使用 Apache 的 .htaccess 来执行此操作,因此您需要 mod_rewrite 模块。在 .htaccess 中,您需要类似的内容:

RewriteEngine on
RewriteRule ^main.php?page=(.+)&id=(.+) /main/$1/$2 [NC]

这应该让您 /main/pages/gettingpaidfortakeingsurveys。这不会对单词进行连字符,我不确定您是否能够在没有过于复杂的情况下做到这一点。

Since you appear to want to do this with Apache's .htaccess, you'll need the mod_rewrite module. In the .htaccess, you'll want something like:

RewriteEngine on
RewriteRule ^main.php?page=(.+)&id=(.+) /main/$1/$2 [NC]

This should get you /main/pages/gettingpaidfortakingsurveys. This won't hyphenate the word and I'm unsure you'll be able to do that without something overly complex.

最好是你 2024-10-05 11:47:48

您尝试过吗?我假设这只是一页的重定向。您需要将其放在 Cake 重写块上方。第二部分必须是完整的 URL:

Redirect 301 /main.php?page=pages&id=gettingpaidfortakingsurveys http://www.domain.com/main/pages/getting-paid-for-taking-surveys
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^$ app/webroot/    [L]
    RewriteRule (.*) app/webroot/$1 [L]
</IfModule>

如果重写是临时的,请用 302 替换 301。url

的 /main 部分看起来不太适合 Cake。不应该只是/pages/...吗?

Have you tried this, I'm assuming that this is a redirect for one page only. You'll need to put it above the Cake rewrite block. The second part must be the full URL:

Redirect 301 /main.php?page=pages&id=gettingpaidfortakingsurveys http://www.domain.com/main/pages/getting-paid-for-taking-surveys
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^$ app/webroot/    [L]
    RewriteRule (.*) app/webroot/$1 [L]
</IfModule>

If the rewrite is temporary, substitute 302 for 301.

The /main part of the url doesn't look very Cake-friendly. Shouldn't it just be /pages/...?

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