-
-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ public function generateRewrite( string $from, string $to, int $type ) : string | |
$toHost = $parsedTo['host'] ?? ''; | ||
|
||
$fromQuery = $parsedFrom['query'] ?? ''; | ||
$toQuery = $parsedTo['query'] ?? ''; | ||
$toQuery = (isset($parsedTo['query']) && $parsedTo['query']!='') ? '?'.$parsedTo['query'] : ''; | ||
|
||
$fromPath = urldecode($parsedFrom['path'] ?? ''); | ||
$toPath = urldecode($parsedTo['path'] ?? ''); | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
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 commentThe 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". There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
Outputs:
Which results in an endless loop because the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
switch( $type ) { | ||
case RewriteTypes::SERVER_REWRITE: | ||
return "{$output}&%{QUERY_STRING}"; | ||
case RewriteTypes::PERMANENT_REDIRECT: | ||
return "{$output} [L,R=301]"; | ||
case RewriteTypes::TEMPORARY_REDIRECT: | ||
return "{$output} [L,R=".RewriteTypes::name($type)."]"; | ||
} | ||
|
||
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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more.
As you have it, it outputs |
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Just to get a shorter ouput... |
||
} catch( GenerationException $e ) { | ||
$output .= $this->generator->comment('ERROR: ' . $e->getMessage() . ': ' . $line); | ||
$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.
The first option will be selected by default. This added logic is unessessary.