0

If you're going to -1 this question, tell me how I can improve it, rather than just leaving it.

This is a dup with a few edits

I'm making an open-source piece of software, but my .htaccess needs a little tuning.

How do I allow a URL such as www.mydomain.net/forum/method/user//abc and keep the // when grabbing it in my PHP code?

I've looked here: allow slash in url .htaccess

But that was no help.

Here's what I have:

.htaccess

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?/=$1 [NC,QSA,L,NE]

And:

geturl.php

$url = (isset($_GET['/']) ? $_GET['/'] : null);
die($url);

Output: account/signup/2/sskssks

URL: account/signup/2//sskssks

Expected output: account/signup/2//sskssks

Basically, something is removing/trimming the // and setting it to /.

Community
  • 1
  • 1
user3650841
  • 73
  • 1
  • 8

1 Answers1

2

Section 3 of RFC 3986 covers the generic syntax of path components in a Uniform Resource Identifier (URI).

  path          = path-abempty    ; begins with "/" or is empty
                / path-absolute   ; begins with "/" but not "//"
                / path-noscheme   ; begins with a non-colon segment
                / path-rootless   ; begins with a segment
                / path-empty      ; zero characters

  path-abempty  = *( "/" segment )
  path-absolute = "/" [ segment-nz *( "/" segment ) ]
  path-noscheme = segment-nz-nc *( "/" segment )
  path-rootless = segment-nz *( "/" segment )
  path-empty    = 0<pchar>
  segment       = *pchar
  segment-nz    = 1*pchar
  segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" )
                ; non-zero-length segment without any colon ":"

  pchar         = unreserved / pct-encoded / sub-delims / ":" / "@"

The line defining segment-nz indicates that individual segments in a path, i.e. /aaa/bbb/ccc ('aaa', 'bbb', and 'ccc' are each segments), cannot be empty. They must contain at least one(1) pchar. There are special cases for beginning an absolute path that is rooted and empty (/) and simply empty, and a couple others that are rarely encountered when discussing Web URLs.

Your URI path is being normalized, stripping the extra / from your path. If that slash is important, you will need to send it as data by using percent encoding.

Community
  • 1
  • 1
William Price
  • 4,033
  • 1
  • 35
  • 54