-
-
Notifications
You must be signed in to change notification settings - Fork 81
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
base: master
Are you sure you want to change the base?
Added R=302 #14
Conversation
No "?" added if no query string fix "public const"
There was a problem hiding this 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"; |
There was a problem hiding this comment.
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…
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 "?"
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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.
fix - no "?" added if no query string
fix - RewriteTypes "public const" compat.
Remove blank line separator