Symfony2 in a subdirectory - .htaccess

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>

Related

Symfony in subfolder of DocumentRoot doesn't include RewriteBase

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?

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 .

CakePHP routing exception in .htaccess file still results in missing controller error

I have a CakePHP 2 install but have certain URLs exempt from the default routing. I did this by adding the exception to the .htaccess file. So for example the call the http://www.mydomain.com/blog or http://www.mydomain.com/proofgallery both redirected to a folder outside of the cakephp.
The .htaccess code looks like this:
# Overrides to the cake routing
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/? (blog|proofgallery)/(.*)$
RewriteRule ^.*$ - [L]
</IfModule>
However, I noticed in the error.log that something causes a missing controller error for those exemptions.
E.g.
2012-10-16 14:49:15 Error: [MissingControllerException] Controller class ProofgalleryController could not be found.
#0 /home/mydomain/public_html/app/webroot/index.php(96): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))
#1 {main}
2012-10-16 11:13:24 Error: [MissingControllerException] Controller class BlogController could not be found.
#0 /home/mydomain/public_html/app/webroot/index.php(96): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))
#1 {main}
Why is that? And how to avoid it? As far as I can tell, all links from within the application use the full URL (http://www.mbvphotography.com/blog) and not the Cake HTML helper, which might explain the missing controller error.
I imagine that you want to add other code but you want to still use Cakephp.
According this your examples, if you want to add http://www.mydomain.com/blog you must go to the following path "app/webroot" of CakePHP and add the folder "blog". For example if you want to use a wordpress with your CakePHP aplication.
Verify that you have the default .htacces on app/webroot/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
And remove the changes you made on the .htaccess.
I If you have more doubts let me know

can't remove index.php with .htaccess

i have installed codeigniter and i want to remove the index.php from url when i access localhost/aplication/index.php. i have set uncomment mod_rewrite.so from httpd.conf en this is my .htaccess file :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
its succes when i acces url from localhost/aplication/index.php/data/users/12 but not with this url localhost/aplication/data/users/12.
how can i fix this??
Try to follow this page about codeignitor pretty urls. Your rules look correct, but I'm terrible with regex.
Some things to look into would be checking if mod_rewrite is available by using phpinfo();. Also step three in that link talks about enabling mod_rewrite using a2enmod. And make sure you restart Apache.
check your config file there should be a line that says:
$config['index_page'] = 'index.php';
You can either set this variable to just '' or you can comment this line out completely, either way it is part of the process of removing the index.php from your codeigniter urls.
this is how you remove the index.php:
htaccess file in the root folder:
RewriteBase /
RewriteEngine on
RewriteCond $1 !^(index\.php|images|js|css|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
for managing some static pages like: example.com/about , example.com/contact, example.com/terms etc
got to config routes file and edit:
//the controller that will be when it is exampl.com
$route['default_controller'] = 'YOUR_MAIN_CONTROLLER_NAME_HERE';
//I creted this for pages that are created dynamically or for displaying error when I want
$route['404_override'] = 'friendlyPages';

vanilla 2 broken links

I have a vanilla 2.0.18b2 installation on my webserver in a subfolder. Forum works, but I can't sign in. When I click a link "sign in" the page goes blank. I think that this is a problem with .htaccess file cause I had a working solution but I wanted to change something and broken the file.
Another thing is that, when I am typing forum.mysite.com it says:
Fatal error: Class 'Gdn' not found in /bootstrap.php on line 47
when I type mysite.com/forum it view the website but with no styling, and when I click a link it goes 500 Internal Error.
Only when I type mysite.com/forum/index.php it looks normal.
My .htaccess file looks like that:
# Modified
# If you modify this file then change the above line to: # Modified
<IfModule mod_rewrite.c>
RewriteEngine On
# Certain hosts may require the following line.
# If vanilla is in a subfolder then you need to specify it after the /.
# (ex. You put Vanilla in /forum so change the next line to: RewriteBase /forum)
RewriteBase /forum/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php\?p=$1 [QSA,L]
#RewriteRule ^$ index.php/$1
</IfModule>
Try clearing the cache by deleting all the files and folders inside the cache folder.
Was facing the exact same problem and clearing the cache solved the issue!
Try changing the RewriteRule to this
RewriteRule ^(.*)$ index.php?p=$1 [QSA,L]

Resources