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

site.yaml redirect with ? in it doesn't work #1983

Closed
jlehtinen opened this issue Apr 18, 2018 · 12 comments
Closed

site.yaml redirect with ? in it doesn't work #1983

jlehtinen opened this issue Apr 18, 2018 · 12 comments
Labels

Comments

@jlehtinen
Copy link

This redirect in /user/config/site.yaml fails because of the question mark. Removing it from the redirect & URL makes it work. Escaping it has no effect.


redirects:
'/dir/tools.htm?param=(.*)': '/dir/$1/another'

(Also, = needs to be unescaped to work. Not sure if this is a bug or how regex works.)

@rhukster
Copy link
Member

I have a fix for this in develop. However, it does not a tweak to your regex. You need to escape the . and the ? as they are special charaters in regex:

redirects:
   '/dir/tools\.htm\?param=(.*)': '/dir/$1/another'

@jlehtinen
Copy link
Author

Wow, that was quick. Thanks so much!

@HunterDG
Copy link

HunterDG commented Aug 13, 2020

Is this related to links with question marks not working when embedded in markdown pages? e.g. https://kb.wisc.edu/page.php?id=47883 (Grav only exposes https://kb.wisc.edu/page.php)

@rhukster
Copy link
Member

as i said in previous comment you have to escape the ? with a \

@rhukster
Copy link
Member

please paste the site.yaml file.

@HunterDG
Copy link

HunterDG commented Aug 13, 2020

this is in default.md, using latest grav/quark theme,

- [test 1](https://kb.wisc.edu/page.php?id=47883)
- [test 2](https://kb.wisc.edu/page.php\?id=47883)
- [test 3](https://kb.wisc.edu/page.php%3Fid%3D47883)
- [test 4](https%3A%2F%2Fkb.wisc.edu%2Fpage.php%3Fid%3D47883) 

@HunterDG
Copy link

HunterDG commented Aug 13, 2020

user/config/site.yaml

title: Title
default_lang: en
author:
  name: 'name'
  email: [email protected]
taxonomies:
  - category
  - tag
metadata:
  description: 'description'
summary:
  enabled: true
  format: short
  size: 300
  delimiter: '==='
redirects: null
routes: null
blog:
  route: /blog

system/blueprints/config/site.yaml

title: PLUGIN_ADMIN.SITE
form:
    validation: loose
    fields:

        content:
            type: section
            title: PLUGIN_ADMIN.DEFAULTS
            underline: true

            fields:
                title:
                    type: text
                    label: PLUGIN_ADMIN.SITE_TITLE
                    size: large
                    placeholder: PLUGIN_ADMIN.SITE_TITLE_PLACEHOLDER
                    help: PLUGIN_ADMIN.SITE_TITLE_HELP

                default_lang:
                    type: text
                    label: PLUGIN_ADMIN.SITE_DEFAULT_LANG
                    size: x-small
                    placeholder: PLUGIN_ADMIN.SITE_DEFAULT_LANG_PLACEHOLDER
                    help: PLUGIN_ADMIN.SITE_DEFAULT_LANG_HELP

                author.name:
                    type: text
                    size: large
                    label: PLUGIN_ADMIN.DEFAULT_AUTHOR
                    help: PLUGIN_ADMIN.DEFAULT_AUTHOR_HELP

                author.email:
                    type: text
                    size: large
                    label: PLUGIN_ADMIN.DEFAULT_EMAIL
                    help: PLUGIN_ADMIN.DEFAULT_EMAIL_HELP
                    validate:
                        type: email

                taxonomies:
                    type: selectize
                    size: large
                    label: PLUGIN_ADMIN.TAXONOMY_TYPES
                    classes: fancy
                    help: PLUGIN_ADMIN.TAXONOMY_TYPES_HELP
                    validate:
                        type: commalist

        summary:
            type: section
            title: PLUGIN_ADMIN.PAGE_SUMMARY
            underline: true

            fields:
                summary.enabled:
                    type: toggle
                    label: PLUGIN_ADMIN.ENABLED
                    highlight: 1
                    help: PLUGIN_ADMIN.ENABLED_HELP
                    options:
                        1: PLUGIN_ADMIN.YES
                        0: PLUGIN_ADMIN.NO
                    validate:
                        type: bool

                summary.size:
                    type: text
                    size: small
                    append: PLUGIN_ADMIN.CHARACTERS
                    label: PLUGIN_ADMIN.SUMMARY_SIZE
                    help: PLUGIN_ADMIN.SUMMARY_SIZE_HELP
                    validate:
                        type: int
                        min: 0
                        max: 65536

                summary.format:
                    type: toggle
                    label: PLUGIN_ADMIN.FORMAT
                    classes: fancy
                    help: PLUGIN_ADMIN.FORMAT_HELP
                    highlight: short
                    options:
                        'short': PLUGIN_ADMIN.SHORT
                        'long': PLUGIN_ADMIN.LONG

                summary.delimiter:
                    type: text
                    size: x-small
                    label: PLUGIN_ADMIN.DELIMITER
                    help: PLUGIN_ADMIN.DELIMITER_HELP

        metadata:
            type: section
            title: PLUGIN_ADMIN.METADATA
            underline: true

            fields:
                metadata:
                   type: array
                   label: PLUGIN_ADMIN.METADATA
                   help: PLUGIN_ADMIN.METADATA_HELP
                   placeholder_key: PLUGIN_ADMIN.METADATA_KEY
                   placeholder_value: PLUGIN_ADMIN.METADATA_VALUE

        routes:
            type: section
            title: PLUGIN_ADMIN.REDIRECTS_AND_ROUTES
            underline: true

            fields:
                redirects:
                    type: array
                    label: PLUGIN_ADMIN.CUSTOM_REDIRECTS
                    help: PLUGIN_ADMIN.CUSTOM_REDIRECTS_HELP
                    placeholder_key: PLUGIN_ADMIN.CUSTOM_REDIRECTS_PLACEHOLDER_KEY
                    placeholder_value: PLUGIN_ADMIN.CUSTOM_REDIRECTS_PLACEHOLDER_VALUE

                routes:
                    type: array
                    label: PLUGIN_ADMIN.CUSTOM_ROUTES
                    help: PLUGIN_ADMIN.CUSTOM_ROUTES_HELP
                    placeholder_key: PLUGIN_ADMIN.CUSTOM_ROUTES_PLACEHOLDER_KEY
                    placeholder_value: PLUGIN_ADMIN.CUSTOM_ROUTES_PLACEHOLDER_VALUE

web.config (combined from imported .htaccess and web.config in webserver-configs)

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
         <defaultDocument>
            <files>
                <remove value="index.php" />
                <add value="index.php" />
            </files>
        </defaultDocument>
       <rewrite>
            <rules>
                <rule name="Imported Rule 1">
                    <match url=".*" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAny">
                        <add input="{QUERY_STRING}" pattern="base64_encode[^(]*\([^)]*\)" ignoreCase="false" />
                        <add input="{QUERY_STRING}" pattern="(&lt;|%3C)([^s]*s)+cript.*(>|%3E)" />
                        <add input="{QUERY_STRING}" pattern="GLOBALS(=|\[|\%[0-9A-Z]{0,2})" ignoreCase="false" />
                        <add input="{QUERY_STRING}" pattern="_REQUEST(=|\[|\%[0-9A-Z]{0,2})" ignoreCase="false" />
                    </conditions>
                    <action type="Redirect" url="error" redirectType="Permanent" />
                    <!-- <action type="CustomResponse" url="index.php" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" /> -->
                </rule>
                <!-- <rule name="Imported Rule 2" stopProcessing="true"> -->
                <rule name="request_filename" stopProcessing="true">
                    <match url=".*" ignoreCase="false" />
                    <!-- <match url="." ignoreCase="false" /> -->
                    <conditions logicalGrouping="MatchAll">
                        <add input="{URL}" pattern="^/index\.php" ignoreCase="false" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php" />
                </rule>
                <!-- <rule name="Imported Rule 3"> -->
                <rule name="ignore_folders" stopProcessing="true">
                    <match url="^(\.git|cache|bin|logs|backup|webserver-configs|tests)/(.*)" ignoreCase="false" />
                    <action type="Redirect" url="error" redirectType="Permanent" />
                    <!-- <action type="CustomResponse" url="error" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" /> -->
                </rule>
                <!-- <rule name="Imported Rule 4"> -->
                <rule name="system_vendor" stopProcessing="true">
                    <match url="^(system|vendor)/(.*)\.(txt|xml|md|html|yaml|yml|php|pl|py|cgi|twig|sh|bat)$" ignoreCase="false" />
                    <action type="Redirect" url="error" redirectType="Permanent" />
                    <!-- <action type="CustomResponse" url="error" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" /> -->
                </rule>
                <!-- <rule name="Imported Rule 5"> -->
                <rule name="user_error_redirect" stopProcessing="true">
                    <match url="^(user)/(.*)\.(txt|md|yaml|yml|php|pl|py|cgi|twig|sh|bat)$" ignoreCase="false" />
                    <action type="Redirect" url="error" redirectType="Permanent" />
                    <!-- <action type="CustomResponse" url="error" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" /> -->
                </rule>
                <rule name="Imported Rule 6">
                    <match url="\.md$" ignoreCase="false" />
                    <action type="Redirect" url="error" redirectType="Permanent" />
                    <!-- <action type="CustomResponse" url="error" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" /> -->
                </rule>
                <rule name="Imported Rule 7">
                    <match url="(^|/)\.(?!well-known)" ignoreCase="false" />
                    <action type="Redirect" url="error" redirectType="Permanent" />
                    <!-- <action type="CustomResponse" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" /> -->
                </rule>
                <rule name="Imported Rule 8">
                    <match url="^(LICENSE\.txt|composer\.lock|composer\.json|\.htaccess)$" ignoreCase="false" />
                    <action type="Redirect" url="error" redirectType="Permanent" />
                    <!-- <action type="CustomResponse" url="error" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" /> -->
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
    <system.web>
        <httpRuntime requestPathInvalidCharacters="&lt;,&gt;,*,%,&amp;,\,?" />
    </system.web>
</configuration>

@HunterDG
Copy link

HunterDG commented Aug 25, 2020

Should I open a new issue? Seems the 'id' attribute on external links is ignored.

['id' attribute not passed through](https://kb.wisc.edu/page.php?id=47883)
[but 'idd' works](https://kb.wisc.edu/page.php?idd=47883)

Using the example from Pass-through of Non-Supported Attributes doesn't work for 'id' attribute

[Pass-through of 'cat and id' attribute](../some-page?classes=underline&cat=black&id=blue)

it's as if &noprocess=id is being enforced somewhere. Is this a setting I can find?

@HunterDG
Copy link

HunterDG commented Aug 25, 2020

I found that if I remove the 'id' attribute from Configuration - System > Markdown > Valid Link Attributes, then they are properly passed through/external links with ?id=blah work!. Is this desired behavior? Seems not but I could be I'm probably misunderstanding "Valid Link Attributes" function.

@mahagr
Copy link
Member

mahagr commented Aug 26, 2020

@rhukster What do you think?

@HunterDG
Copy link

HunterDG commented Sep 20, 2020

Apologies - I have realized I misunderstood, added id back to Valid Link Attributes (target already exists), and decided to try &noprocess=id per Skip Certain Attributes, but...

[Skip Certain attributes](../some-page?id=myvariable&classes=underline&target=_blank&noprocess=id,classes)

results in:

<a href="/grav/some-page?id=myvariable&classes=underline&target=_blank">Skip Certain attributes</a>

NOT

<a href="/grav/some-page?id=myvariable&classes=underline" target="_blank">Skip Certain attributes</a>

system.yaml:

pages:
  markdown:
    valid_link_attributes:
      - id
      - rel
      - target
      - class
      - classes

@hughbris
Copy link
Contributor

You need to escape the . and the ? as they are special charaters in regex:

redirects:
   '/dir/tools\.htm\?param=(.*)': '/dir/$1/another'

Submitted a PR to Learn documenting this. It's pretty important when migrating a legacy site with good pagerank that uses query strings heavily.

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

No branches or pull requests

5 participants