Skip to content

Trailing Slashes not working #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
xblabs opened this issue Dec 23, 2013 · 5 comments
Closed

Trailing Slashes not working #12

xblabs opened this issue Dec 23, 2013 · 5 comments

Comments

@xblabs
Copy link

xblabs commented Dec 23, 2013

http://www.domain.com/path/ gets internally resolved to http://www.domain.com/path.

Now, if the server is configured for SEO / DC reasons to generate a 404 response / doc if that trailing slash is missing, Houston has a problem.

one solution would be :

public function setPath ($path) {
        $this->info['path'] = array();

        foreach (explode('/', $path) as $dir) {
            if ($dir !== '') {
                $this->info['path'][] = $dir;
            }
        }
        $this->info['trailingSlash'] = preg_match( '`\/$`', $path );
        $this->buildUrl();
    }

and in buildUrl()

...

if (isset($this->info['fragment'])) {
            $url .= '#'.$this->info['fragment'];
        }

        if( $this->info['trailingSlash'] ) {
            $url .= '/';
        }

        if (!$maintainCache && ($this->url !== $url)) {
            $this->clearCache();
        }
...

@oscarotero
Copy link
Collaborator

Are you sure this happens? The setPath method not only stores the path, but also the file.
For example: http://domain.com/path1/path2/ is proccessed to:

$this->info['path'] = array('path1', 'path2');
$this->info['file'] = '';

but this url: http://domain.com/path1/path2

$this->info['path'] = array('path1');
$this->info['file'] = 'path2';

So, on generate the url again, the trailing slash should be respected

@xblabs
Copy link
Author

xblabs commented Dec 23, 2013

Yep, the explode - and re implode takes it away. I had a quick peek in Xdebug.

oscarotero added a commit that referenced this issue Dec 23, 2013
@oscarotero
Copy link
Collaborator

Ok, I've made some changes. Can you confirm that it's working now?

@xblabs
Copy link
Author

xblabs commented Dec 24, 2013

Working in my test case ;) Thanks!

@oscarotero
Copy link
Collaborator

Thank you for the feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants