I'm got some problem with Route in Laravel 4.2. Here is details:
I have an example route:
Route::get('users', function(){return 'some-thing'});
and the route still work normally at http:://localhost:8000/users.
However, when I create a subfolder inside public folder, its name is "users".
--public
--users
That link didn't work and return the folder index. I know that is a big sercurity problem.
How to fix it? Can you please help me?
I wouldn't say a huge security problem, if there is sensitive data in that folder, then it shouldn't be in "public". You could deny directory listings (assuming Apache virtualhost or .htaccess):
Options -Indexes
As in Laravel's (and most other frameworks') .htaccess file, it only uses the "Router" if the file or directory doesn't exist. This is common as shown below:
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Related
I am trying to install Laravel in an old project.
I tried to place my existing project files from /www folder into /public folder.
Now I am facing some issues.
1) I tried to rename the Laravel's index.php to laravel.php and same in .htaccess but it did not work. I am doing this to avoid the conflict with my index.php
2) My project has following /www/.htaccess file and uses routing using mod_rewrite_delegator.php file. I have not idea how to handle this part.
If I user myproject.com/events this does not work but myproject.com/events/dashboard.php works. So I need Laravel to find the route from my old project first and then under Laravel routing.
Here are my existing .htaccess code
Options -Indexes +FollowSymLinks
RewriteEngine on
# quick links
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !/user_files/
RewriteRule ^([^\.\?]+)$ /mod_rewrite_delegator.php?keyword=$1 [QSA,L]
ErrorDocument 404 /http_404.php
Thank you
In DirectAdmin, I have changed the domainname of my project. But unfortunately it did not gave me the result I was looking for. So I undid my action. But, that did not solve the problem.
At first, I was able to access my site.com/public folder to use the assets for my website. But after my failure Laravel handles the /public directory as a route. So, I dan't have access anymore to my public folder and needed assets.
My domain: good2beout.nl
Can anyone help me?
P.s. I already looked at question Laravel 4 - public directory being treated as a route - image not showing but this does not solve my problem.
I have found my problem.
I accidentally overwrote my .htaccess file, replaced it with
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
https://laravel.com/docs/4.2#pretty-urls
I've used a route name as "webmaster" (www.domain.com/webmaster) and symfony shows me an error like:
NotFoundHttpException: No route found for "GET master"
And my htacces is:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /web/app.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
I know, "web" is reserved keyword in a Symfony2 Application. How i use this exception in my project.
Thanks.
Symfony's web directory should be your site's document root, and as such, does not need to be included in the path as the base of your rewrite rule.
So, assuming your .htaccess file is located at PROJECT_ROOT/web/.htaccess then all that should be required is this
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
Again, this assumes that you've set up Apache to point to PROJECT_ROOT/web as the site's document root (where PROJECT_ROOT would be something like /var/www/vhosts/symfony_project)
Reacting to your comment
I don't have a static route as "webmaster". It's dynamically generated in a controller. For example: path: /{category}
I guess you need to add a prefix to your route.
In exemple, how can symfony know if www.myapp.com/admin is a route one of your dynamic route or a standard route?
You need to have at least a prefix like /site/{category}
I have looked at several examples of htaccess configs for websites within sub-directories, and tried most of them without 100% success.
My setup is:
using Yii framework
htaccess at public_html/.htaccess
site located inside public_html/mysite directory
index handling all requests located at public_html/mysite/frontend/www/index.php
The status of the URLs:
www.mysite.com works fine [ok]
www.mysite.com/controller/action shows me the homepage [wrong]
www.mysite.com/mysite/frontend/www/controller/action works fine [wrong, the item above should work instead]
My .htaccess at the moment looks like this:
AddHandler application/x-httpd-php53s .php .html
Options +SymLinksIfOwnerMatch
IndexIgnore */*
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !^/mysite/frontend/www
RewriteRule ^(.*)?$ /mysite/frontend/www/index.php [L]
I have tried everything, but I have no idea why www.mysite.com/controller/action won't work :(
Any help would be really appreciated! Thanks!
I found the answer to this similar question to be helpful. Here is how my rewrite rules ended up:
#Forward all non-existent files/directories to Yii
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) subdir/index.php/$1 [QSA,L]
This takes all non-existent files/folders and sends them to the yii script with initial url appended. QSA appends any query string that may be present in the initial url.
You didn't mention if you configured Yii's Url Manager for clean URLs. You need to, otherwise Yii expects the "route" to appear as a GET param named "r". If you didn't, consult this section of the definitive guide
You dont need to edit .htaccess. You just need to move the Yii entry script (index.php) and the default .htaccess up from the subdirectory to the webroot (so that they reside directly under public_html). Once you move index.php and .htaccess to the root directory, all web requests will be routed directly to index.php (rather than to the subdirectory), thus eliminating the /subdirectory part of the url.
After you move the files, you will need to edit index.php to update the references to the yii.php file (under the Yii framework directory) as well as the Yii config file (main.php). Lastly, you will need to move the assets directory to directly the webroot, since by default, Yii expects the assets directory to be located in the same location as the entry script).
That should be all you need to do, but if you need more details, I describe the approach fully here:
http://muhammadatt.tumblr.com/post/83149364519/modifying-a-yii-application-to-run-from-a-subdirectory
I also didn't update the .htaccess file, easier to modify the httpd.conf virtual host for the subdomain and change the DocumentRoot to point to your yii folder.
I am using zend framework with Apache sever on Ubuntu. When I try my site on localhost, I use following url
for example:
http://test.dev/authentication/login
http://test.dev/student/profile
Where 'authentication' refers to AuthenticationController and 'login' refers to loginAction.
'student' refers to StudentController and 'profile' refers to profileAction.
Question: Now I want to use phpBB forum with my site. I had to use the following URL to start phpBB forum with my website.
http://localhost/test/forum/
Where 'test' is my main project(website) directory. I want to use following URL for phpBB forum.
http://test.dev/forum/
How to configure my project to open phpBB forum using above URL? Should I create a controller?
Thanks
I guess you are using apache mod_rewrite with your ZF application.
The simplest solution is to place a new .htaccess file inside the forum/ directory and turn off the rewrite engine
RewriteEngine Off
This works because Apache first look for the .htaccess file in the requested directory, if it does not find one, he looks in the parents folder and so on until it reaches the public directory. When you request /forum/ he finds the .htaccess file there and turns off the RewriteEngine.
After some time I have found my answer. I just placed my 'forum' folder in 'public' folder and it is working for me without changing my .htaccess file.
Here is my settings:
My directory structure is now like this:
/var/www/test/public/index.php
/var/www/test/public/.htaccess
/var/www/test/public/forum
My httpd.conf entry is like this:
<VirtualHost 127.0.0.1>
ServerName test.dev
DocumentRoot 'C:\wamp\www\test\public'
</VirtualHost>
My .htaccess file is like this(it controls both folder and controller/action URLs):
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Last line in above .htaccess file allow me to use my URL without index.php in URL.
After above setting I am able to use following URLs correctly:
http://test.dev/authentication/login
http://test.dev/student/profile
http://test.dev/forum/
In above URLs 'authentication' and 'student' are controllers. 'login' and 'profile' are actions and forum is a directory
Comments are welcome.
Thanks
This will work as well:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(js|ico|gif|jpg|png|css)$ /index.php
If you place phpBB in the public folder the webserver will be able to see it and the 2nd two lines of this code will exclude "real files" and "real folders" from the rewrite which is what you want for the forum folder. Obviously the last time, pushes all framework traffic to the index.php file.