简体   繁体   中英

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 . 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]/ . In that folder there's an index.php file and a .htaccess file that reads:

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/ . The "something" folders obviously don't really exist and our system just picks them up from the htaccess and goes from there.

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. 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."

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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