laravel 5 removing public from url not working on WAMP - laravel

Many people post that following htaccess works for removing "public" from url. But i am working on WAMP and this is not working:
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
This shows following Error message from Laravel framework:
Sorry, the page you are looking for could not be found. 1/1 NotFoundHttpException in RouteCollection.php line 161:
There are other methods to remove "public" from url but I want to understand why this method is not working on my side which people followed frequently in their posts. my url is : http://localhost/laravel/ (directory: d:/wamp/www/laravel)
Can any one help me to understand why this popular method is not working on my side? Is their any issue in Laravel internal routing as I think my htaccess is working properly?
Thanks a lot in Advance.

I am sorry this is not exactly what you wanted but... Instead of rewriting the path, go to your Apache config and change your directory so it includes /public as well. That way you will get rid of the now necessary public from the URL. I know it is not an answer to your question, so please do not downvote. Nevertheless, it should solve your problem.

Your router is not picking up the redirected path because your laravel installation is a subdirectory within your webserver and the RewriteRule ^(.*)$ is picking up the whole path which includes /laravel. This is being appended to public/ because it's captured in $1.
The simplest case for you may be to alter the RewriteRule to not capture the laravel directory.
eg:
ReqriteRule ^laravel/(.*)$ public/$1 [L]
You may or may not need a forward slash ^/laravel/(.*)$ ...
Alternatively, (and more correctly) you should setup a virtual host within your apache configuration to serve the laravel application in the root of a virtual host (as it's designed) or you might be better off in the long run using Laravel Homestead as a preconfigured development environment.

Related

Laravel .htaccess not working on deployment host

I have just tried to deploy a my Laravel app to a shared hosting and it seems like the .htaccess is causing an internal server error, if I delete it all the files in /public can be accessed. I have checked several of the other answers here, but no one solved the problem. I have checked all the required modules
When deploying your app to a shared hosting, make sure that your domain or subdomain is pointing to the public folder in your laravel application. When asked for the document root path point it to Eg.
/public_html/laravel_project/public
Try that to see if you are still facing issues
I finally looked into the hosting service's docs and in their examples it's
RewriteRule ^ /index.php [L]
with a trailing slash instead of just
RewriteRule ^ index.php [L]
Don't know why but that made the difference and now works both on my localhost and the deployment host.

Remove /Public from url in Laravel

Good Day!
Hello,
Currently I was working on laravel and im new on it. I keep looking a solutions on my problem and i couldn’t find a solution on this. My laravel work is accessible already without /public in the url I fix this thru .htaccess, but it can be access also with /public in the url. Please see links below for your reference.
https://utok.ph/
https://utok.ph/public
my htaccess file
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
.htaccess files wont work on this, what i did is i update the root directory in my server side.
instead the root will be at public_html I change it to public_html/public

How to solve TinyMce image manager Network Error

It was working until my hosting do some changes to server. I don't know what changes they have made.
request is: click here
or
http://mysite.com/tiny_mce/plugins/imagemanager/js/compressor.php?classes=mox.Event,mox.List,mox.DOM,mox.geom.Point,mox.geom.Rect,mox.String,mox.dom.Drag,mox.tpl.Template,mox.tpl.Paging,mox.data.ResultSet,mox.net.Cookie,mox.ui.WindowManager,mox.ui.Menu,mox.ui.MenuItem,mox.ui.DropMenu,mox.ui.DropMenuItem,mox.dom.Layer,mox.dom.Tween,mox.net.JSON,mox.dom.Form,mox.util.Dispatcher,moxiecode.manager.BaseManager,moxiecode.manager.ImageManager,moxiecode.manager.DevKit
it returns NetworkError: 404 Not Found
if i remove mox.net.Cookie and mox.net.JSON by hand from the querystring it works.
What should be the problem? How can i solve it.
I use CodeIgniter.
Thank you.
If you're using .htaccess it may be possible you're heading to a CI controller rather than the file you're looking for.
Here is an example mod_rewrite rule that might help. Often it's worth checking your access log to see which file is being called also.
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|media|favicon\.ico|ipadicon\.jpg|tiny_mce)
RewriteRule ^(.*)$ /index.php/$1

Codeigniter: Routes only visible when entering /index segments

I'm working on my first project with codeigniter 2.0 and have a bit of a problem.
On my localhost (a MAMP installation) everything works fine with the routes. Only when i add a copy on my domain, change the base url and other necessary settings like my database settings it works fine for like 99%. I can't access my other controllers directly without adding the /index route. For example when i want to visit the http://my_domain.com/work it'll open the 404 error page but when i enter ttp://my_domain.com/work/index it works fine. Does someone know a setting i have to change for the online version? The Htaccess files are identical.
CHeers in advance.
I found my solution. I just checked the routes.php file in my config where i added a route for every controller. I just removed these and only my default_controller route is left. Now it works fine. Just a codeigniter newbie issue.
Thanks anyways for the help #Hibiscus and #BigFatBaby
I sorted my problem by setting the following line as my .htaccess file.
RewriteEngine On
RewriteRule ^.*$ index.php [NC,L]
It'll rewrite anything after the /index.php/blaha to /blaha.

using mod_rewrite to redirect from subdomain to maindomain

My problem is that i have a functioning subdomain (sub.mydomain.com). sub is loaded in mydomain.com/sub.
What i would like to do is to redirect all requests to sub.mydomain.com to mydomain.com.
Somehow it seems that when im the subdomain i cannot access the rootfolder (main domain). I can get it working with from mydomain.com/sub to mydomain.com. But not from the subdomain.
Currently im using:
RewriteEngine on
RewriteRule ^(.*)/?$ /home/web/webuser/$1 [L]
When accessing sub.mydomain.com i get a 500 Internal Server Error.
Is there a restriction in accessing the main from a sub? (rights wise)
Or maybe another way of getting to main, perhaps something like (../$1)
Thanks
EDIT:
I only have access to .htaccess. So DocumentRoot cannot AFAIK be used in .htaccess file.
What about symlinks? I dont really know what it does, but i assume that it links two locations? The only code i found for that enables symlinks (Options +FollowSymlinks) - but this line doesnt say anything about what to link (perhaps im all wrong)
Btw. thanks for input so far !
I must admit that I did not fully understand your question. Do you want to redirect everything from sub.mydomain.com/whatever to mydomain.com/whatever? In that case, the following (put in the config file of your sub.mydomain.com) might work:
RewriteEngine On
RewriteRule ^/(.*)$ http://mydomain.com/$1 [R,L]
It redirects on the client side, meaning that the user will see mydomain.com/sub in the browser.
EDIT: I think I understand your question now. Yes, it's a permissions issue: If the DocumentRoot of your web site is /whatever/sub, then you cannot just access /whatever by adding "/.." to the URL. I hope you understand that this is a good thing. :-) mod_rewrite just changes the URL, so it cannot do that either.
So, to solve your problem, you need to either change the DocumentRoot of sub.mydomain.com or create a symlink that allows you to access the required directory (e.g. /whatever/sub/redir-target -> /whatever). Be careful with the symlink option, though, since it will create valid directories of infinite length on your file system (/whatever/sub/redir-target/sub/redir-target/...) and some scripts cannot cope with that.
EDIT2: Instead of a symlink, you might want to create an alias, e.g., something like this:
Alias /redir-target /home/web/webuser
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/redir-target/.*$
RewriteRule ^/(.*)$ /redir-target/$1
Still, I think the easiest solution is to change the DocumentRoot...
Why not try using a Redirect Directive from mod_alias?
It's difficult to provide a definitive answer without knowing more about your server configuration.
The following might work and is at the very least a decent starting point:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.mydomain\.com
RewriteRule (.*) /$1 [L]
Ideally that would go in your httpd.conf, but might work from a .htaccess file (again, more information about how your subdomains are setup would be helpful).

Resources