mod_rewrite 工作不一致

发布于 2024-08-12 19:20:57 字数 715 浏览 1 评论 0原文

我正在进行一个重写计划,效果很好。基本上,url 中的任何内容都会作为查询字符串传递到 index.php,因此 /dave/bob 被重写为 /index.php?page=dave/鲍勃。我在 index.php 中处理这个解析。这是我的 .htaccess:

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

我遇到的问题是有时 URL 在地址栏中显示不正确。请参阅以下两个示例:工作不工作。服务页面也会出现同样的问题。对于那些不想访问外部链接的人,goldseal.skilldrick.co.uk/contact 显示为 goldseal.skilldrick.co.uk/contact/?page=contact< /em> 在地址栏中。

正如您将看到的,我目前正在一个子域中工作,该子域正在使用 cpanel 重定向到 /public_html 下的目录。可能是这个原因吗?

I've got a rewriting scheme going on that was working fine. Basically, anything in the url is passed as a querystring to index.php, so /dave/bob is rewritten to /index.php?page=dave/bob. I deal with the parsing of this in index.php. Here's my .htaccess:

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

The problem I'm having is that sometimes the url is displaying incorrectly in the address bar. See these two examples: working and not working. The same problem occurs with the services page. For those of you who'd rather not visit external links, goldseal.skilldrick.co.uk/contact is displaying as goldseal.skilldrick.co.uk/contact/?page=contact in the address bar.

As you'll see, I'm currently working in a subdomain, which is being redirected to a directory under /public_html, using cpanel. Might this be the cause?

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

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

发布评论

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

评论(2

紫南 2024-08-19 19:20:57

尝试在index.php 前面加上“/”。

Try putting a "/" in front of index.php.

╭ゆ眷念 2024-08-19 19:20:57

好吧,我是个白痴,但我已经解决了!

services 和 contact 都引起问题的原因是因为我在 public_html/goldseal 下已经有名为 /services 和 /contact 的目录(来自该站点的先前版本),因此当我告诉它转到 / 时,重写规则变得混乱接触。

感谢您的帮助,很抱歉浪费您的时间:P

Ok, I'm an idiot, but I've worked it out!

The reason services and contact were both causing problems was because I already had dirs under public_html/goldseal called /services and /contact (from a previous incarnation of the site), so the rewrite rule was getting confused when I told it to go to /contact.

Thanks for all your help, and sorry for wasting your time :P

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