mod_rewrite 工作不一致
我正在进行一个重写计划,效果很好。基本上,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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试在index.php 前面加上“/”。
Try putting a "/" in front of index.php.
好吧,我是个白痴,但我已经解决了!
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