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

.htaccess redirect has no effect on route #29

Open
Chibi86 opened this issue Nov 19, 2016 · 4 comments
Open

.htaccess redirect has no effect on route #29

Chibi86 opened this issue Nov 19, 2016 · 4 comments

Comments

@Chibi86
Copy link

Chibi86 commented Nov 19, 2016

Anax use REQUEST URI to extract route, REQUEST URI stays the same even after .htaccess has redirect, PHP SELF is better for it takes effect by the .htaccess redirect.

Replace
$requestUri = $this->getServer('REQUEST_URI');

With:
$requestUri = $this->getServer('PHP_SELF');

At line 120 in src\Request\CRequestBasic.php

@mosbth
Copy link
Owner

mosbth commented Nov 19, 2016

Could you give some additional info on the problem and how to reproduce it? Do you have some test case for it, or usecase?

@Chibi86
Copy link
Author

Chibi86 commented Dec 22, 2016

Here is test example on REQUEST_URI problem
RewriteRule ^theme/([a-zA-Z0-9_()-]+)(/)?$ theme.php/$1 [NC,L] in .htaccess
$app->router->add('theme/regions', function() use ($app) in theme.php

It's should only need to check after regions for theme just stands for 'theme.php/', but REQUEST_URI not response to .htaccess redirect so it still searching for 'theme/regions'.

A example on PHP_SELF
RewriteRule ^p/([a-zA-Z0-9_()-]+)(/)?$ page/page/$1 [NC,L] in .htaccess
$di->set('PageController', function() use ($di) { $controller = new Anax\TextContent\PageController(); $controller->setDI($di); return $controller; }); in index.php
public function pageAction in PageController.php

PHP_SELF response to .htaccess redirect and no need for mess up routes...

@mosbth
Copy link
Owner

mosbth commented Feb 17, 2017

I guess you did that change and made it work for you. In that case all is well.

However, it looks a bit odd, the rewritepart. I think I would have written it like this:
RewriteRule ^(theme)/([a-zA-Z0-9_()-]+)(/)?$ theme.php/$1/$2 [NC,L] in .htaccess
$app->router->add('theme/regions', function() use ($app) in theme.php

This would be the way I would expect it to work.

Its a bit tricky to extract the route part, and there are a few things to deal with to make it right. I am aware of at least one condition where the current extraction does not work as intended (related to rewrite on virtual hosts - not using htaccess).

You might be right about PHP_SELF, but I would need to do a more detailed investigation before I would know and actually get into the code to change it.

I found a good explanation on how PHP_SELF and REQUEST_URI gets populated.

@Chibi86
Copy link
Author

Chibi86 commented Mar 11, 2017

RewriteRule ^(theme)/([a-zA-Z0-9_()-]+)(/)?$ theme.php/$1/$2 [NC,L] in .htaccess
or
RewriteRule ^theme/([a-zA-Z0-9_()-]+)(/)?$ theme.php/$1 [NC,L] in .htaccess
Doesnt matter when REQUEST_URI is active.

RewriteRule ^(theme)/([a-zA-Z0-9_()-]+)(/)?$ theme.php/$1/$2 [NC,L] in .htaccess
~rabe13/dbwebb-kurser/phpmvc/me/kmom04/webroot/theme/regions/ result of REQUEST_URI
~rabe13/dbwebb-kurser/phpmvc/me/kmom04/webroot/theme.php/theme/regions result of PHP_SELF

RewriteRule ^theme/([a-zA-Z0-9_()-]+)(/)?$ theme.php/$1 [NC,L] in .htaccess
~rabe13/dbwebb-kurser/phpmvc/me/kmom04/webroot/theme/regions/ result of REQUEST_URI
~rabe13/dbwebb-kurser/phpmvc/me/kmom04/webroot/theme.php/regions result of PHP_SELF

I change now to $requestUri = $this->getServer('PHP_SELF') . "?" . $this->getServer('QUERY_STRING');, as REQUEST_URI send with querystrings.

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

2 participants