Skip to content
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

Trailing slash in sitemap.xml link to the sub-sitemaps #173

Closed
XhmikosR opened this issue Jul 20, 2018 · 8 comments
Closed

Trailing slash in sitemap.xml link to the sub-sitemaps #173

XhmikosR opened this issue Jul 20, 2018 · 8 comments
Labels
need info Need more information on the issue

Comments

@XhmikosR
Copy link
Contributor

XhmikosR commented Jul 20, 2018

Hello!

I'm having an issue where the sub-sitemaps have a trailing slash in /sitemap.xml.

https://foo.bar/sitemaps/1/section/pages/1/sitemap.xml/

My .htaccess section that's related to this:

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Force a trailing slash
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} /+[^\.]+$
    RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]

    # Send would-be 404 requests to Craft
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
    RewriteRule (.+) index.php?p=$1 [QSA,L]
</IfModule>

This happens even without my custom rule to force trailing slashes. I do have addTrailingSlashesToUrls set to true though.

I'm using Craft CMS 3.0.16.1 and SEOmatic 3.1.2.

@khalwat
Copy link
Collaborator

khalwat commented Jul 20, 2018

That's very strange... perhaps you need to add xml to defaultTemplateExtensions? https://docs.craftcms.com/v3/config/config-settings.html#defaulttemplateextensions

I'm not sure why Craft would be adding a / to those URLs.

@khalwat khalwat added the need info Need more information on the issue label Jul 20, 2018
@XhmikosR
Copy link
Contributor Author

Tried that, still the same :/

@XhmikosR
Copy link
Contributor Author

If I set addTrailingSlashesToUrls to false then this goes away.

@khalwat
Copy link
Collaborator

khalwat commented Jul 20, 2018

Weird, it looks like with that setting, Craft will add that to any URL, regardless of whether there is a file extension on it or not:

From UrlHelper.php:

        // Put it all together
        if (!$showScriptName || $generalConfig->usePathInfo) {
            if ($path) {
                $url = rtrim($baseUrl, '/') . '/' . trim($path, '/');

                if (!$cpUrl && $generalConfig->addTrailingSlashesToUrls) {
                    $url .= '/';
                }
            } else {
                $url = $baseUrl;
            }
        } else {
            $url = $baseUrl;

            if ($path) {
                $pathParam = $generalConfig->pathParam;
                $params = $pathParam . '=' . $path . ($params ? '&' . $params : '');
            }
        }

@XhmikosR
Copy link
Contributor Author

Should I report this to Craft then? I just happened to notice the issue in sitemap.xml.

@khalwat
Copy link
Collaborator

khalwat commented Jul 20, 2018

You can; I'm not sure if it's a bug or intended behavior. Seems a little odd to me but who knows?

Worst case, I can just rtrim() the URLs, but I wouldn't think it'd blindly add a / to anything passed in to UrlHelper::siteUrl() if it has a file extension.

@XhmikosR
Copy link
Contributor Author

OK, I made an issue upstream craftcms/cms#3123

@khalwat
Copy link
Collaborator

khalwat commented Jul 21, 2018

Looks like P&T fixed it for an upcoming release of Craft CMS: craftcms/cms@1ec8cd1

@khalwat khalwat closed this as completed Jul 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need info Need more information on the issue
Projects
None yet
Development

No branches or pull requests

2 participants