简体   繁体   English

为什么我在没有尾部斜杠的情况下获得404页面但是它与尾部斜杠一起使用?

[英]Why am I getting a 404 for a page without the trailing slash but it works with the trailing slash?

I have an app that allows users to create and build a site. 我有一个允许用户创建和构建网站的应用程序。 Let's call it system.com . 我们称之为system.com When a user creates a site with a domain (say domain.com ) they have forwarded to our nameservers, it creates folders and adds their domain to our server through the cPanel API to a folder like system.com/[user id]/[site id]/ . 当用户创建具有域(例如domain.com )的站点时,他们已转发到我们的域名服务器,它会创建文件夹,并通过cPanel API将其域添加到我们的服务器,如system.com/ [user id] / [网站ID] / In that folder there's an index.php file and a .htaccess file that reads: 在该文件夹中有一个index.php文件和一个.htaccess文件,其中包含:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)/$ index.php?page=$1 [L]

I won't go into too much detail about how it works from there, but basically the user can create pages like domain.com/something/something-else/ . 我不会在那里详细介绍它是如何工作的,但基本上用户可以创建像domain.com/something/something-else/这样的页面。 The "something" folders obviously don't really exist and our system just picks them up from the htaccess and goes from there. “东西”文件夹显然不存在,我们的系统只是从htaccess中选择它们并从那里开始。

My problem is that domain.com/something/something-else/ works but domain.com/something/something-else returns a 404. I've been doing research and trying many things but can't seem to get it working. 我的问题是domain.com/something/something-else/有效,但domain.com/something/something-else返回404.我一直在做研究并尝试很多东西,但似乎无法让它工作。 Any ideas? 有任何想法吗? Thanks in advance. 提前致谢。

Edit : 编辑

I should have mentioned what I've tried so far. 我应该提到我到目前为止所尝试的内容。 I've tried changing the rewriterule to work regardless of the trailing slash, like so: 无论尾部的斜线如何,我都尝试将重写改为工作,如下所示:

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

And other variations of that. 以及其他变种。

I've also tried different methods of forcing a trailing slash but none of those worked either. 我也尝试了不同的强制尾随斜杠的方法,但这些方法都没有。

I think you want your rule to look like this: 我想你希望你的规则看起来像这样:

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

Which says : "Any number of any characters optionally followed by a slash should be changed to index.php?page=$1 where $1 is the characters you found before the slash. Also disregard any other rules that you find if this one matches." 其中说:“任意数量的任意字符可选地后跟斜杠应更改为index.php?page = $ 1,其中$ 1是您在斜杠之前找到的字符。如果匹配,则忽略您找到的任何其他规则。”

its based on your url rewrite access rule.. 它基于你的网址重写访问规则..

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

as you can see index.php?page=$1 is aliased into / and all the requests is sent to index.php 你可以看到index.php?page = $ 1别名为/ ,所有请求都发送到index.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM