Jump to content

$page->path always has trailing slash in spite of template settings


DrQuincy
 Share

Recommended Posts

I'm not sure if I'm missing something glaringly obvious here but if you set URLs (not segments) to not have trailing slashes you will still get one at the end when accessing $page->path.

So $page->path for my sitemap.xml file is /sitemap.xml/. Yes if you visit /sitemap.xml/ it redirects to /sitemap.xml — but why doesn't it just return /sitemap.xml? This will end up adding an awful lot of unnecessary requests.

Is this intended behaviour?

I have also noticed the API only seems to work with forward slashes too (e.g. parent=/foo/bar/, not parent=/foo/bar) — but I get that as a design decision since the the trailing slash setting is effectively abstract from that.

Link to comment
Share on other sites

Ah, thanks, yes, that explains it.

I always assumed $page->url was the full URL but that is actually httpUrl;

var_dump(wire('pages')->get('/sitemap.xml/')->path); // "/sitemap.xml/"
var_dump(wire('pages')->get('/sitemap.xml/')->url); // "/sitemap.xml"
var_dump(wire('pages')->get('/sitemap.xml/')->httpUrl); // "http://site.local/sitemap.xml"

Thanks, I will use ->url in future. ?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...