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

Url rewrite patterns in settings.json - equivalent of apache's mod_rewrite #81

Closed
GoogleCodeExporter opened this issue Aug 28, 2015 · 16 comments

Comments

@GoogleCodeExporter
Copy link

Mongoose web server has an option named "url_rewrite_patterns". We should allow 
for adding url rewrite patterns to settings.json. Instructions should be 
provided with examples on how to make work existing Apache patterns with 
Mongoose. For example:

    <IfModule mod_rewrite.c>
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
    </IfModule>

What would be the equivalent in Mongoose?

Some frameworks do not make it easy to disaable pretty urls and url rewriting. 
So we should definitely support it.

Original issue reported on code.google.com by [email protected] on 10 Feb 2014 at 3:33

@GoogleCodeExporter
Copy link
Author

[deleted comment]

1 similar comment
@GoogleCodeExporter
Copy link
Author

[deleted comment]

@GoogleCodeExporter
Copy link
Author

I've had a look at the Mongoose docs over at 
http://cesanta.com/docs/Options.shtml, and it looks like mongoose takes a 
parameter "-url_rewrites" that allows you to specify any URL rewrite options. 
However, there does not seem to be any method yet to implement these in the 
settings.json.

It's pretty essential to get url rewriting implemented, as previously stated, 
many PHP frameworks just won't work without this.

Original comment by [email protected] on 11 Jun 2014 at 3:07

@GoogleCodeExporter
Copy link
Author

<IfModule mod_rewrite.c>
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

Mongoose equivalent:

'mongoose -url_rewrites **=www/index.php'

Unfortunately this would lose the "$1" part of the RewriteRule, as Mongoose's 
rewrite options are not as powerful as Apache's mod_rewrite. So if we're using 
Mongoose, people who want to use Frameworks that require this kind of thing 
might be out of luck.

Original comment by [email protected] on 11 Jun 2014 at 3:17

@GoogleCodeExporter
Copy link
Author

@comment #4 toady.bomb
We can always modify Mongoose sources to add support for the $1 parameter in 
url rewrites. We already use a custom version of Mongoose that was modified to 
provide several fixes and new features.

Original comment by [email protected] on 11 Jun 2014 at 8:23

@GoogleCodeExporter
Copy link
Author

[deleted comment]

1 similar comment
@GoogleCodeExporter
Copy link
Author

[deleted comment]

@GoogleCodeExporter
Copy link
Author

[deleted comment]

@GoogleCodeExporter
Copy link
Author

See Issue 137 and the __fix_mongoose_env_variables() php function that fixes 
issues with Mongoose environment variables when using urls like 
"index.php/company/5".

Original comment by [email protected] on 27 Oct 2014 at 8:03

@GoogleCodeExporter
Copy link
Author

Added support for pretty urls with basic url rewriting for 404 errors in 
revision 190fbae92d05.

Example usage is in the pretty-urls.php script:
https://code.google.com/p/phpdesktop/source/browse/phpdesktop-chrome/www/pretty-
urls.php

See the ["web_server"]["404_handler"] option on the Settings wiki page:
https://code.google.com/p/phpdesktop/wiki/Settings#web_server

PHP Desktop Chrome 31.8 was not yet released, but you can download the main 
executable from the alternative download site. Direct link:
https://www.dropbox.com/sh/3ihzy40v62em613/AABqIRiSNXVqjZra_-nG2kGia/phpdesktop-
chrome-31.8.exe?dl=0

Original comment by [email protected] on 27 Oct 2014 at 11:46

  • Changed state: Fixed

@GoogleCodeExporter
Copy link
Author

Reopening issue. Current implementation of pretty urls has problems with POST 
requests. Issue was reported on Forum 
(https://groups.google.com/d/msg/phpdesktop/NLZnCUqveUQ/20SmPXH4XVQJ). This is 
due to 302 redirect being made when pretty url is accessed. It needs to be 
investigated if a 302 redirect can be made using the original POST method. 
According to this 
(http://stackoverflow.com/questions/8138137/http-post-request-receives-a-302-sho
uld-the-redirect-request-be-a-get) Chrome may have problems with that.

Original comment by [email protected] on 28 Oct 2014 at 8:05

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

307 Temporary Redirect should be made to preserve POST data. See for reference:
 * https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_Redirection
 * http://stackoverflow.com/questions/2068418/whats-the-difference-between-a-302-and-a-307-redirect

Original comment by [email protected] on 28 Oct 2014 at 8:14

@GoogleCodeExporter
Copy link
Author

Using 307 redirect fixes the issue. Unfortunately using redirect to access 
pretty urls during POST requests has a side effect when reloading page. After a 
post request is made, F5 reload causes request method to be changed to GET. It 
also affects Back/Forward navigation.

Current implementation needs to be rethinked. An alternative implementation 
without the need for a redirect when accessing pretty urls would require 
changes in mongoose.c > convert_uri_to_file_name(), somewhere around the url 
rewriting code.

Original comment by [email protected] on 28 Oct 2014 at 9:44

@GoogleCodeExporter
Copy link
Author

Fixed issues with POST requests when accessing pretty urls. New implementation 
does not depend on redirects anymore.

Fixed Mongoose environment variables: REQUEST_URI, PHP_SELF and others. It is 
no more required to use __fix_mongoose_env_variables() php func.

Updated pretty-urls.php example.

Changes in revision 39c81a7b2b24.

phpdesktop 31.8 executables was updated on dropbox.

Original comment by [email protected] on 29 Oct 2014 at 10:41

  • Changed state: Fixed

@GoogleCodeExporter
Copy link
Author

Fixed C memory issues in revision 2600acd0a30e. Executable on dropbox was 
updated.

Original comment by [email protected] on 29 Oct 2014 at 11:36

@GoogleCodeExporter
Copy link
Author

Project will move to Github. Find this issue at the new address (soon): 
https://github.com/cztomczak/phpdesktop/issues/81

Original comment by [email protected] on 24 Aug 2015 at 3:26

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

No branches or pull requests

1 participant