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

Added R=302 #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Added R=302 #14

wants to merge 1 commit into from

Conversation

lolalalol
Copy link

fix - no "?" added if no query string
fix - RewriteTypes "public const" compat.
Remove blank line separator

No "?" added if no query string
fix "public const"
Copy link
Owner

@donatj donatj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've got some stuff indented with spaces, some stuff indented with tabs. Please reformat with tabs.

Please consider my feedback and get the tests into a passing state and I will re-review.

@@ -48,7 +48,7 @@ public function generate( string $input, int $type, bool $comments ) : string {
}

$output .= $this->generator->generateRewrite($explodedLine[0], $explodedLine[1], $type);
$output .= "\n\n";
$output .= "\n";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just messes up the output formatting…

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to get a shorter ouput...

@@ -63,20 +63,22 @@ public function generateRewrite( string $from, string $to, int $type ) : string
}
}

$output .= 'RewriteRule ^' . preg_quote(ltrim($fromPath, '/'), ' ') . '$ ' . $this->escapeSubstitution($prefix . ltrim($toPath, '/')) . '?' . $toQuery;
$output .= 'RewriteRule ^' . preg_quote(ltrim($fromPath, '/'), ' ') . '$ ' . $this->escapeSubstitution($prefix . ltrim($toPath, '/')) . $toQuery;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix - no "?" added if no query string

The trailing question mark is actually very important and there for a reason. It tells Apache not to forward given GET parameters.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it adds a blank query string which messes up for a true "friendly URL rewriting".
If you do not add QSA in the rewrite rule options, no query string will be given.
My experiences with your tool show me that this is not necessary to end with "?"

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is as designed. It is designed to do the exact rewrite the user enters. Nothing more.

If you do not include a query string, a query string should not be included. If the user wants a query string, they can include a query string. Doing what the user told us to do is the more friendly option.


As you have it, the rewrite:

foo.html?bar=10 foo.html

Outputs:

RewriteCond %{QUERY_STRING} (^|&)bar\=10($|&)
RewriteRule ^foo\.html$ /foo.html [L,R=301]

Which results in an endless loop because the ?bar=10 is appended to the redirected URL.

image

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I only used it without query string in "from" URL.
We can cancel this pull request ?
I'll work on my fork only.

}

throw new InvalidArgumentException("Unhandled RewriteType: {$type}", $type);
}

private function escapeSubstitution( string $input ) : string {
return preg_replace('/[-\s%$\\\\]/', '\\\\$0', $input);
//return preg_replace('/[-\s%$\\\\]/', '\\\\$0', $input);
return $input;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what you're up to here?

Escaping substitutions is important.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My experiences with your tool show me that this is not necessary to escape the rewrited URL.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

foo.html bar%20baz.html is an example of where it is necessary.

As you have it, it outputs RewriteRule ^foo\.html$ /bar baz.html&%{QUERY_STRING} which results in an internal server error. The space needs to be escaped.

<option value="<?= RewriteTypes::SERVER_REWRITE ?>" <?php echo $paramType === RewriteTypes::SERVER_REWRITE ? ' selected' : '' ?>>
Rewrite
</option>
<option value="<?= RewriteTypes::TEMPORARY_REDIRECT ?>" <?php echo $paramType === RewriteTypes::TEMPORARY_REDIRECT ? ' selected' : '' ?>>302</option>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first option will be selected by default. This added logic is unessessary.

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

Successfully merging this pull request may close these issues.

2 participants