Symfony can't find assets prefixed with web/ on local - image

I'm running the most recent version of Symfony through Mamp. I have some image assets prefixed with /web/ in my code base. Symfony can't seem pull them up when I go to my local url (u.local).
An example image asset url would be (relative path): /web/productEditor/image.png
In mamp under additional parameters for <directory> I have:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
I can't change the local code to just remove the /web/ part of the img src tag. Is there a way to configure .htaccess to ignore the "/web/" part of the url?
Can I configure Symfony to differently through mamp?
Directory Structure:
Web Root
-Web Folder
--App.php (what boots up symfony)
--productEditor
---Assets
Thanks.

You question doesn't tell me where your app expect the images to be. if its looking for them in /productEditor/image.png in stead of /web/productEditor/image.png then the following may solve your issue. ( but i have not tested this )
RewriteCond %{REQUEST_URI} ^/web/
RewriteRule ^web/(.*)$ /$1 [QSA,L]
With the full .htaccess block you have listed above it would be.
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/web/
RewriteRule ^web/(.*)$ /$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
-Nathan

Related

How to deploy Laravel Project on Google Cloud Virtual Machine?

I'm trying to deploy my Laravel project on Google Cloud VM, it did directing to my index.php file but it supposed to routing to the controller instead of showing the index.php code line.
Here is the result
Then i try to change the .htaccess file like the code below:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
#I'm adding this code
RewriteRule ^(.*)$ public/$1 [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
And here is the result
After that i remove that line and try to change all the 'AllowOverride None' lines to 'AllowOverride All' inside of apache2.conf file, then remove the lines that prevent .htaccess and .htpasswd files from being viewed by Web clients:
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
But the result is still same like the first result
And then i'm trying to add this line:
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
inside of apache2.conf file but then again the result is still same like the first result
I already install Composer inside of the project but it still not working.
Thank you.
P.S: Sorry for my bad English.

Laravel 5.8 showing 404 Not Found errors

I change the index.php file path public to root. After adding a .htaccess file in the root path (laravel 5.7) every page working fine. But in laravel 5.8 when I click another page, it's showing 404 Not Found.
My .htaccess file is below.
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
#Send request via index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d``
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
The content of a Laravel .htaccess file should look like this:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Your webroot has to be set to the /public directory. Don't try to search for other solutions that move the index.php and .htaccess file from /public to the root directory of your Laravel application. There is absolutely no reason why you want to move the webroot from /public to /. index.php sits in /public for a reason. If your webhost does not offer the ability to move the web root to another directory switch your hoster.
It might be that you have created your folder as Example and trying to access it via example
ie
localhost/Example/public
yet accessing it like
localhost/example/public

Laravel showing directory file instead of redirecting to public/index.php

I am kinda new to Laravel and I am trying to do the next thing:
I have a Centos 7 running Apache and PHP on which I have different web apps running.
I have all apps in /var/www/html under folders and index.php links them all. Now i installed composer, Laravel and added a new Laravel project in /var/www/html/play/play1.
The problem is that when I try to access https://example.com/play/play1 I should get the Laravel index page (the one under public/index.php) correct?
Instead I get a directory with all Laravel project files.
If I access https://example.com/play/play1/public I can see the index page.
I've searched it over and I checked if AllowOverwrite all is present, if mod_rewrite is on. Inside public folder there is a .htaccess file.
Can anybody who dealt which such a problem help me please ?
Within the root of the project folder (where you see app/ resources folders etc) create a .htaccess file and paste the below:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
Laravel's root directory should not be the one accessed publicly - you have to point to public/ directory (where the index.php and .htaccess are located).
So in your server config http://example.com/play/play1 should point to var/www/html/play/play1/public

Images can be load in Phalcon

My images are not loaded with Phalcon Framework.
Maybe because the .htaccess file. I don't know.
The framework return this error:
"ImgController handler class cannot be loaded", when access http://domain.com/img/tiger.jpg
The route "http://domain.com/projects/update/1" is OK.
My .htaccess files below.
#/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
#/public/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>
What's worng ?
Thanks anyway.
It appears to be a routing problem, especially if something works and something isn't. Phalcon digests the uri, finds a route, but cannot dispatch the ImgController. Check that the naming is correct, that your have the correctly named controller (ImgController not ImageController), that it has the correct namespace. If doesn't help, add your routing configuration details and your ImgController and where it is located.

Removing index.php and handling subdomains of two Codeigniter sites, when one within the other

I have two Codeigniter sites, one sitting within the subdirectory of the other. I need some help modifying my htaccess file to remove index.php from both.
The first site, http://subdomain.domain.com is stored in /home/sites/subdomain/www/html/
The second, http://test.subdomain.domain.com lives in /home/sites/subdomain/www/html/app_staging/
This is my .htacess file from /home/sites/subdomain/www/html/:
RewriteEngine On
# Rewrite the main domain
RewriteCond %{HTTP_HOST} !test.subdomain.domain.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
# Rewrite the sub domain
RewriteCond %{HTTP_HOST} test.subdomain.domain.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/(.*)$ /app_staging/index.php?/$1 [L]
This is removing index.php from the from the first site, everything is ok there. On the second site, I can load the default controller form http://test.subdomain.domain.com, but subsequent pages return a 404 from the server. What are my next steps?
You should put each of two .htaccess files inside their own root CI folder.
Personally, I prefer restricting requested files and/or folders in order to prevent them from being treated by RewriteRule.
So, for the first file which is located at /home/sites/subdomain/www/html/:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico|public)
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
And for the other one is located at /home/sites/subdomain/www/html/app_staging/:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico|public)
RewriteRule ^(.*)$ /app_staging/index.php/$1 [L]
</IfModule>
Note: You must add css and other folders (like public) to RewriteCond if you don’t want them to be treated by RewriteRule.
As a side-note: You might want to prevent directory listing by using the following inside each .htaccess file:
<IfModule mod_autoindex.c>
Options -Indexes
</IfModule>

Resources