How to stop Laravel directory errors - php

Is there a way in laravel to make directory accesable without Laravel having to get involved?
I recently ported a Wordpress website for my brother into Laravel (which I am new to) and all of the image paths are hard coded in the body of the blog article.
The issue I am having is that the url it need to read the image at is:
http://www.theunlikelytraveller.co.uk/wp-content/uploads/2015/11/DSC_0728.jpg
but laravel doesn't like that.
Here's the article: http://www.theunlikelytraveller.co.uk/posts/a-return-to-the-beautiful-balkans
Can anyone help?

If you want to force Laravel to ignore wp-content directory, for example, you can edit .htaccess file inside a public directory:
RewriteRule ^wp-content - [L,NC]
This line should be added before other rules.

Related

Sync Laravel Production Code using Git

Currently my local code and production code follow the same directory structure. After, pushing my changes from local, i pull it on the server and it works fine.
Website path is something like http://abcde.com/code/laravel/public
code directory is under version-control
Now, i'm trying to change path to http://abcde.com
i followed this guide and thinking about moving source code out of server directory. So, the structure:
/var/www will contain content of laravel's public folder
/var/source will contain laravel
But then how'll i manage it with Git because the structure will be different?
Edit: I'm aware of two solutions:
Changing apache root
use .htaccess to remove public
For 1, there is a possibility that we'll add another directory admin in www, which will have its own source code. So, existing content of www will be moved to a sub-directory.
For 2, It's not recommended to keep source code inside web server root.
Please correct me if i'm wrong.
My thought is, you can make symlinks to preserve your directory structure, with this you help apache to keep it original configuration, and at the same time will no have any issues with version control.
Symlink is by using this command: ln -s /path/to/origin path/to/destination.
Bests ;)
There is a simpler procedure. Pull you complete project in var/www and add a .htaccess in var/www which contains -
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
Now you will be able to use http://abcde.com

Laravel 5.1 show indexes for existing folders

I have a problem with Laravel 5.1 routing, If I try to make a route with the same name that a folder in the /public folder apache shows me the index of the folder (I have forbidden indexes so it shows a Forbidden message) I don't know if it's impossible to make it work, I have obviously changed the name of the assets folder with the conflictive name in public directory, but it would be awesome if I could name it as I want.
If I wans unclear (because my bad english) the short explanation is the following:
I have a "game" folder in the /public folder of Laravel 5.1
I want to have a route named /game (example.com/game)
When I acces to /game apache shows me the index of the folder, instead of redirect me to index.php as rewrite rules do.
Thanks in advice
In your htaccess file there is something like this: if there is no file or directory for the URL then give the URL to laravel.
Just remove the directory check and it should work fine. (Please post your htaccess file so I can tell you what line you have to remove)

Affect on security of Laravel 5 when change folder structure to remove public folder

I'm new in Laravel 5.
I found this Laravel 5 - Remove public from URL on Stack Overflow to remove public folder from my Laravel 5 App. Only I have a question about the security.
When I am removing public from URL, then I have to change the basic folder structure of Laravel 5. Yes, it's working fine without the public from the URL.
But what's about the security of Laravel, because I am changing the default folder structure? Is it secure to use?
You should be pointing your Apache host root to the $LARAVEL_PATH/public directory instead of $LARAVEL_PATH.
The point of having sub directory for www host root instead of project root is that you're not leaking any of your project files through your web server.
Even though all the PHP files have the file suffix .php, malicious user can access your $LARAVEL_PATH/storagedirectory and its subdirectory contents, read your composer.json or package.json to find vulnerable dependencies or read .env file etc.
If you're running on shared hosting and you have mandatory public_html, try installing Laravel outside of that public_html directory and either removing public_html (if empty) and replace it with symlink to $LARAVEL_PATH/public OR if you want the Laravel instance to be subdirectory ofpublic_html, do the same but create symlink from$LARAVEL_PATH/publictopublic_html/$PROJECT_SUBDIR`.
That public directory is there for reason to make project a bit more secure. Solve the actual problem and don't try to break this simple but nice security addition. :)
you this link you provided is not about changing the actual file structure of the framework, this example uses mod_rewrite to rewrite the url of your application. In other words you are telling your server that you would like to point to that directory without the full path is visible to the end user.
Also take a look on the below answers of the link you've provided.
Rename the server.php in the your Laravel root folder to index.php and
copy the .htaccess file from /public directory to your Laravel root
folder. -- Thats it !! :)

error invalid controller specified in zend framework after upload to another folder

My problem is, when i upload my project into hosting:
http://172.20.30.43/psm/CB11011/
i got this error
An error occurred
Page not found
Exception information:
Message: Invalid controller specified (psm)
this is my full domain link..
http://172.20.30.43/psm/CB11011/carrental/public/user/register
But if i access in localhost,it look fine. This is my url for localhost..
localhost/carrental/public/register
The true controller is "register", not the psm.. for the base url i already add a line into application.ini, this is my code :
resources.frontController.baseUrl = "http://172.20.30.43/psm/CB11011/carrental/public/"
the problem path for css,js or another include file in layout.phtml look fine. They can link to right path, the only error is zend framework wrong pick my controller.. what should i do guys??
i'm sorry for my explaination, i'am new with zend framework, Don't know how to explain well using term in zend framework.. this is my first project using zend framework.
The problem is that your application is in an subfolder in your hosting environment. This way zend thinks (with this call http://172.20.30.43/psm/CB11011/) that it should access the controller psm and call the action CB11011. Simply change your .htaccess file inside you /public directory.
Something like this (untested!!!) should be fine:
RewriteEngine on
RewriteRule (.*) ./psm/CB11011/$1
And change the path to the frontcontroller inside your application.ini:
resources.frontController.baseUrl = "/psm/CB11011"
PS: There a some security concerns about putting the whole application into a subfolder, since your controller/modules might be accessible!
Try just inserting the following:
RewriteBase /psm/CB11011
into your .htaccess file, where psm/CB11011 is the subdirectory you moved the application to.

How do I get CakePHP configured so it shows up correctly in my browser?

I am a cakephp newbie and I had trouble to view the files under the view folder through browser.
I used cakephp console to bake model, controller and views. (ex: Invoices_controller.php for controller, invoice.php for model and a invoices folders under views folder). According to the tutorial I read, I can access the invoice view by typing http://localhost/myProject/invoices
(there is no index.php inside the invoices folder..but the tutorial shows it still can display a page. no idea how they did it)
The path for my invoices is myProject/views/invoices and there add.ctp, index.ctp, edit.ctp files inside the invoices folder.
The browser showed the file is not found when I typed http://localhost/myProject/invoices
You have some lack in your knowledge about how the webserver handling a request when cakephp is installed. Assume that we use apache.
In cake's folder structure you can see .htaccess files in the root, app and webroot directories what have url rewrite rules in them. At the end a normal request to a cakephp site will be transformed to a http://site.url.root/app/webroot/index.php?url=original.url
In nutshell to understand it in your point of view:
That index.php call the required php files and at least a cakephp app object is built up in the memory with the required models and methods. Then the app object let say start and calls its methods (model, controller and view methods) and at the end it gives back a result to apache what serves it to you.
Therefore the original url path is a "non existent" virtual url.
If you enter http://localhost/myProject/ do you get a cake intro page? If so does it highlight any problems?
It sounds to me as if you do not have Apache set up properly. I don't know what OS you're using, but it might be worth checking this link, written for Ubuntu, to make sure all is well: http://leoponton.blogspot.com/2010/05/getting-cakephp-up-and-running-on.html
I fixed the same problem.
if you are using windows 7 os, wamp server, cakephp 2.2.3. then
goto apache -> http.conf -> open -> search for mod_rewrite -> uncomment the line LoadModule rewrite_module modules/mod_rewrite.so
Now restart your server, now it should work fine.
Jerry, I think the issue is this. You have put the CakePHP folder in the root of localhost. I would propose that you create a virtual host pointing the myProject so the url becomes:
http://myProject/accounting
This may solve your problem. Be sure rewrite module is on. Also, when you point the virtual host to myProject, it should be the APP folder of the cakephp. If you want to run multiple projects off the same core, you can set them up like so:
/var/www/cake
/var/www/html/myProject
/var/www/html/myProject2
The /var/www/cake directory is where you drop the cake core. Under this directory you will have cake, app, plugins, vendors, etc. the myProject(2) directories will be the contents of the app directory.
Now, to get this to work, you need to go to /var/www/html/myProject/webroot/index.php and edit it to point to the cake directory in /var/www/cake. This will then load the core when rewrite points to index.php in webroot. You should be good to go!

Categories