Symfony in subfolder of DocumentRoot doesn't include RewriteBase - .htaccess

I have a weird situation with Symfony 3.2.6. The whole code is above public_html directory which is a DocumentRoot.
In public_html I have a directory called panel. In this directory I have put app.php and app_dev.php controllers with .htaccess. I have setup properly require and include_once paths.
The problem is that when I run mydomain.com/panel/app_dev.php I get an error:
No route found for "GET /panel/app_dev.php"
So it seams that this code in .htaccess doesn't work properly for this situation.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
So I have commented out this and used this after RewriteEngine On
RewriteBase /panel/
but this gives the same result. Anyone knows how to fix it?

Related

website transfer from folder in public_html to public_html caused errors

I just transferred my website from example.com/newsite to example.com by moving the folder where everything was stored (newsite) into my public_html to make it the root domain. Now I am receiving multiple issues on my error_log and the website is loading very very slowly. The error log is telling me things like:
PHP Warning: current() expects parameter 1 to be array, boolean given in /home3/example/public_html/newsite/wp-content/plugins/lezada-addons/includes/templates/lezada_brands_grid.php on line 79
I was thinking the urls containing example.com/newsite should be rewritten via .htaccess
Will this resolve the problem? If so what would the rewrite code be? I tried:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example.com\newsite$ [NC]
RewriteRule ^(.*)$ "http://example.com/$1" [R=301,L]
</IfModule>
But this isn't working and the website is down!

Mod Rewrite .htaccess folder

I'd like to rewrite my parameter from www.example.com/admin/account?account=activity-log to www.example.com/admin/account/activity-log and I don't know how to do that properly. Here's my current .htaccess code:
RewriteEngine on
RewriteRule ^account/([^/]*)$ /admin/account.php?account=$1 [L]
That works well but that only gives me like this www.example.com/account/activity-log. I want to include the folder named admin/. I tried to add the admin folder before the account/ like this:
RewriteEngine on
RewriteRule ^admin/account/([^/]*)$ /admin/account.php?account=$1 [L]
but that only gives me 500 internal server error, please help.
Assuming your code is in: [doc_root]/admin/.htaccess, then probably best to declare a rewritebase. Try this:
RewriteEngine On
RewriteBase /admin/
RewriteRule ^account/([^/]+)$ account.php?account=$1 [L]

Symfony2 in a subdirectory

I am trying to configure a Symfony 2.3.3 project into a subdirectory named dev to access it like so :
www.mydomain.com/dev/
Thing is, it is correctly calling the front controller but I get the following error :
NotFoundHttpException: No route found for "GET /dev/"
Well, I don't like the idea to change all my routes in the routing.yml file. So I tried manipulating the .htaccess files with RewriteBase, but I could not found the solution.
Is there some config to change to Symfony in order to get this to work ?
Do I need to change anything in a .htaccess file ?
I use the following web/.htaccess file : Symfony standard web/.htaccess
My root .htaccess just contains this :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/phpmyadmin
RewriteRule ^(.*)$ web/$1 [QSA,L]
</IfModule>

How to deploy Symfony2 on a shared-hosting?

I want to access my symfony app in production env (http://www.sample.com/amateur1/web/app.php) from this url http://www.sample.com/amateur1.
To do that I moved the .htacces file to http://www.sample.com/amateur1/.htaccess with this contents:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
But when I go to http://www.sample.com/amateur1 shows a 404 Error, and prod.log isn't written.
I also used RewriteBase /amateur1/web/ because I don't know If RewriteBase path is relative to the DocumentRoot of the server, Or from the path where the .htaccess file is located. Also tried /amateur1 and /amateur1/ as RewriteBase due to this answer Symfony2: How to deploy in subdirectory (Apache)
With the three try's, The Exceptions page appears unstyled, and not loading any image. But then I get the following error in prod.log file:
[2013-02-15 02:06:47] request.ERROR: Symfony\Component\HttpKernel\Exception\NotFoundHttpException: No route found for "GET /amateur1/" (uncaught exception) at /home/u105859802/public_html/amateur1/app/cache/prod/classes.php line 5121 [] []
What I'm doing wrong ?
In your configuration, apache uses public_html as the document root
If Symfony2 is installed in directory /home/u105859802/public_html/amateur1, the Symfony public directory to serve is /home/u105859802/public_html/amateur1/web/
You should use
RewriteBase /amateur1/web/
But beware, it is not safe
You have to protect your symfony directories! (configuration is accessible)
Why don't you try moving your symfony files in your private area ?
You can rename the Symfony web directory to public_html
See how to do that in documentation cookbook
So, my recommendation structure looks like below :
/home/u105859802/
vendor
src
app
bin
public_html (web by default in symfony2) <- the only public directory
In most of the shared hosting, you can't override Apache settings in that case may need to wright a redirection rule in .htaccess file
Options +FollowSymLinks +ExecCGI
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
RewriteRule !^projectName/ /projectName/web/app.php/%{REQUEST_URI} [L,NC]
this is the rule I used in my project .
You may need to provide full paths to your assets other ways they will not get loaded .

Cake php Sub Folder Installation, Temp folder errors from htaccess or file permissions?

My client has asked for a cake php app i've made for them to go into a sub directory on their existing server.
All works perfectly on my test remote and local installations.
Initially I had a problem with htaccess and had to add RewriteBase /quotesystem/ to my htaccess files in order to see the site at all. So I have changed my htaccess as below:
cake root .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /quotesystem/
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
app .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /quotesystem/app/
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
and webroot .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /quotesystem/app/webroot/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
</IfModule>
Now I can access my site but i get loads of warnings about the temp directory:
Warning (2): SplFileInfo::openFile(/web/sites/_p/_e/_t/petersen-stainless.co.uk/public/www/quotesystem/app/tmp/cache/persistent/cake_core_cake_en-gb) [function.SplFileInfo-openFile]: failed to open stream: No such file or directory [CORE/Cake/Cache/Engine/FileEngine.php, line 295]
You can see it here: http://www.petersen-stainless.co.uk/quotesystem
Now, i've CHMOD the temp directory to 777 so everyone should have permissions but i still get these errors.
I've deleted all of the files in these folders so that the temp directories have been cleaned.
When I use my ftp client - transmit - to look at the file permissions the owner appears as (?) and if i try to change it i get an error:
Could not change owner of “tmp”. Server said: 'SITE CHOWN' not understood
I dont get this with any other site I work on.
I don't understand enough to know what is going on, is this a permissions problem or an .htaccess problem or both? Or is it a server configuration problem?
If anyone can help shed some light on this and help my understanding i'd be very grateful.
UPDATE:
My directory structure on the server is as follows:
-- public
--- www
----- quotesystem
------- lib
------- app
--------- config
--------- webroot
In my experience, the SplFileInfo warning appears when Cake attempts to read/write cache that it does not have permission to access. Make sure your application has permission to read/write the cache/tmp folder (depending on your Cake version).
It's probably a .htaccess problem. The RewriteBase should be the same for both the webroot and app .htaccess. So the line in both files should be:
RewriteBase /quotesystem/
I personally never touch the .htaccess in the Cake root directory as it doesn't seem to be necessary to alter anything there.
In addition, /tmp/cache and it's subdirectories should be writable as well.

Resources