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
Make trailing slash rewrite use relative path #3145
Conversation
I have the same problem (subdir, but no RewriteBase, never needed that), but your proposed fix doesn't work for me, got redirected to:
Yep, it's Windows, it's on local, I don't want to create virtual host for each project, etc. Exotic, I know. Considering how dealing with .htaccess is always such a pain, I'd personally handle this at PHP level. If anyone could suggest better .htaccess directives? |
success 😃
Also, working on %{REQUEST_URI} should be robuster. Last but not least, successfully tested with GET parameters. jakezatecky, would you please give it a try too? and for reference: 343c31e |
@vlakoff, I agree, I would probably change the
My solution was flawed, as you noted. The issue you experienced is mitigated if you use |
Glad to hear :) Please add the directory condition in your PR, I think it's a must. Then, it is important to use Summary:
Side note: for debugging these redirects, I have to use Chrome and clear browser cache every time. Firefox keeps giving me stale results. |
Makes sense. For what it's worth, I was successfully able to test both Firefox and Chrome while clearing the cache/history. |
Looks like it's also fine with Firefox now; it's just I remember having had trouble with it previously. @taylorotwell If you agree, the code is ready to merge. This time, promised :) Summary: Fix trailing slash redirect when app located in a subdirectory. |
👍 |
Why not? |
Probably because Taylor has said before Laravel should be run from a domain root. It would be lovely if this could be reconsidered. |
For the genesis and some extra explanations: laravel/laravel#3145
For the genesis and some extra explanations: laravel/laravel#3145
This has revealed itself to be quite popular. Considering I have developed for clear reference my answer on SO, could this issue be reconsidered? (Ah, and… mine is robuster than yours was :p) |
This has been added to Laravel, finally: #4344 🙌 |
The "Redirect Trailing Slash"
RewriteRule
does not use a relative path. Instead, it uses an absolute path to the web root. This causes an issue if you addRewriteBase
to.htaccess
.To see this problem in action, consider the following `.htaccess:
If we make a request to
http://some-site.com/newbase/file/
, we will be redirected tohttp://some-site.com/file
, which is incorrect.By changing the RewriteRule to
RewriteRule ^(.*)/$ $1 [L,R=301]
, you now get redirected to the correct location:http://some-site.com/newbase/file
Granted, you could argue that since this issue would only come up if you edit the
.htaccess
file and add theRewriteBase
rule, you should know to change the correspondingRewriteRule
. However, if you know little about.htaccess
files, you might spend an hour trying to figure out why you were redirected to the web root when an extra slash was added at the end.It's important to note that this change does not appear adversely affect anything if we still use the web root.